how to deserialize php string in iOS - php

Here is a string sample that I get from my DB which is maintained in php. I am not sure as how to use it in my iPhone as to extract various values:
a:27:{s:26:"the-muse_disable_post_meta";s:5:"false";s:31:"the- muse_disable_published_date";s:4:"true";s:23:"the-muse_disable_author";s:5:"false";s:24:"the-muse_disable_coments";s:5:"false";s:19:"the-muse_page_title";s:13:"default_title";s:21:"the-muse_custom_title";s:0:"";

Change the response to a JSON Array and you can simply parse it in every coding language.
PHP
echo json_encode($array);

Related

how to remove hidden junk character after php json encode

I was created JSON array from json_encode using PHP. I gave my array to json_encode . It's created JSON array very well. And i feed this JSON array to my android apps. When i am gonna read this url at android it's return following EXCEPTION ERROR.
Error parsing data org.json.JSONException: Value  of type java.lang.String cannot be converted to JSONObject
But when i am gonna create jason object at android adding this following line
jObj=new JSONObject(json.substring(json.indexOf("{"), json.lastIndexOf("}") + 1));
It's working perfectly.
But i don't want to need the my second type solution. I need the php solution when i am put my json_encode on php.
And also at IOS the JSON return NULL values. How can i fix in both IOS and Android
Thanks advance
The java.text.Normalizer is intended to do exactly this: remove unwanted unicode characters.
The normalize method will allow you to pass your CharSequence and return the "normalized", ASCII-only String.

Parsing Form JSON output with PHP

How do I go about parsing the json request below in PHP to extract specific values (in value ) like the following: studentName, studentemail and courseName? There will be only one entry per request and I will not need the rest of the values. I need to store these as PHP variables to be written to MYSQL. The parsing is where I am having trouble
See json below
{"count":7,"data":[{"name":"Timestamp","ordinal":0,"value":"3/5/2013 2:45:31 PM"},{"name":"studentName","ordinal":1,"value":"mikejones"},{"name":"studentEmail","ordinal":2,"value":"mikejones%40gmail.com"},{"name":"courseName","ordinal":3,"value":"Grade%20Test"},{"name":"cpQuizInfoPassFail","ordinal":4,"value":"Fail"},{"name":"cpInfoPercentage","ordinal":5,"value":"75"},{"name":"institutionCode","ordinal":6,"value":"1212"}]}{"count":0}{"subject":"Course Transcript","footer":"Thank you for your participation!","footerURL":"https://sites.google.com/site/test393223837/googleformsdemotranscript/footerLogo.jpg","correctURL":"http//abc.com,"enabled":true,"correctResponseText":"Correct Response","showCorrectAnswers":true,"description":"Please keep this for your records as proof of course completion and certification.","incorrectURL":"https://sites.google.com/site/test3232393837/_/rsrc/1342229575450/googleformsdemotranscript/redX.png","fromName":"The Training Team","replyTo":"","headerURL":"https://sites.google.com/site/test3938232337/googleformsdemotranscript/CaptivateDev.jpg","isHTML":true,"title":"Course Transcript","to":"joe#gmail.com","userResponseText":"Your Response"}
You can use json_decode function, that parse json code to php objects and arrays. See documentation for more info.
One problem is your json is invalid. Check with:
http://jsonlint.com/ or
http://jsonformatter.curiousconcept.com/

Show php print_r in Flash?

Trying to figure out a way to get ActionScript to print out a php object. In PHP, I can just do print_r, and I'm able to successfully get the object into Flash, but now can't figure out how to print out the object using ActionScript 3?
Well, when the request first comes over, there is always URLLoader.data, which is data in its raw form. If you're looking to get the data from a JSON-style object, there is for( var i:String in obj ). If you're looking for things more obscure than that, there is the ability to use describeType. My favorite example of the last one is in the JSONEncoder class.
From PHP, you can encode most objects to JSON using json_encode() (PHP5+). Using the AS3 JSON decoder from as3corelib you can then convert that encoded string into an oject that AS3 con read. After that you can iterate over the object as key/value pairs and output it however you wish.
I think I know what you mean, I had the same need, so I made this
http://www.actionscript.org/forums/showthread.php3?t=266979
scroll to the bottom, there is a description and an .AS file called trace_r that I wrote

Can I get a data from PHP server to Android application with JSON?

I am not sure about understanding about JSON, PHP, and MySQL.
In my plan, I will create a web server and android application.The database server is MySQL. In my understanding, PHP can send data and encode it into a JSON array, how can I use this JSON array in my Android application?
following is PHP code...
<?php
mysql_connect("host","username","password");
mysql_select_db("Deal");
$sql=mysql_query("select * from CITY where CITY_NAME like 'A%'");
while($row=mysql_fetch_assoc($sql))
$output[]=$row;
print(json_encode($output));
mysql_close();
?>
here is a nice article link. i hope you like it, and if you have any question, you can ask, i will try to solve it as soon as possible.
Your question is difficult to understand.
It seems like you're asking how to send JSON data using PHP.
Use the PHP json_encode and json_decode functions to convert between JSON and PHP arrays.
To send a JSON string, first convert the array to JSON using json_encode(), then print the resulting string and exit the program.
<?php
$my_array = array('this'=>'is', 'just'=>'an', 'example'=>'array');
$json_string = json_encode($my_array);
print $json_string;
die;
?>
Hope that helps.

How to send array datatype to server?

I am using PHP as server side coding, and i want a set of values to be send to the server(in array format). how can i send that, and retrieve that array value at backend?
Encode it as a JSON string and decode it using PHP json_decode
Use JSON.stringify (the source is available here) to convert your array to string at JavaScript end.
Send this string to your PHP page using an XMLHttpRequest.
In the PHP code, read the string from the $_POST variable and call json_encode on it.
Send the array as a json string, en then use json_decode

Categories