iPhone POST JSON to PHP expecting return for login/receiving data
OK, I am quite new to this Objective-C and JSON thing, so please bare with my questions. I am using Stig Json Framework and ASIHTTPRequest.
My overall objective is to send JSON data (containing login credential) to a PHP webservice and expecting a return once the PHP process the data. I need an authorize key from the return and also specific user data tied to the login credential.
Now, I can send the JSON data via POS开发者_如何学CT all right, consume the data via PHP all right. But I just don't understand the logic of the return data, as I said earlier. I only know that ASIHTTPRequest do return the response string via anything echo'ed from the PHP, but is this the correct way to get the return data I want?
Or, do I encode it back to JSON? How?
I think another viable solution is to write a webservice that receive parameters via URL and return JSON data. For example, how do I write http://search.twitter.com/search.json?q=@<name>
?
The data is returned as a JSON string and you need to convert it to Objective-C object using the "JSONValue
" method before working with the returned data.
For example:
NSDictionary *results = [jsonString JSONValue];
Now you can work with the returned data as an NSDictionary
.
You can json_encode
data from PHP and echo that. Now you will receive JSON data in the ASIHTTPRequest delegate method, that is, a response string. Then use it as you like.
Remember to set the header type to json
while you echo data from PHP.
精彩评论