I’m developing an Server-Client application in Xcode 4.2
The application saves some user informations and sends them in a HTTP GET request to server via server url.
As response, I have text like this:
2011-12-30 15:44:02.120 smartHome[340:f803] {
button = 1;
key = 181abc88e57c37a42769;
message = (
{
ID = 1;
date = "2011-12-10 16:00:00";
message = asdf;
status = 1;
"user_id" = 2;
}
);
"wrong_user" = 0;
}
(2/Jan/2012)
Sorry for such confusing edits but i haven’t overcome my deal yet. I need to parse this JSON text(i think it is called text:) and do some implemetations on the results.. I have to use, for example, the message object and its status value, if status equals to 1 i will trigger a Notification in my App. As like that, if the button comes me as a value with 1 i will send a POST to the server and request for the button id and title attributes..
There are a lot of tutorials about parsing but all i saw are about Twitter or flickr APIs, unfortunately i couldnt desing a clear way to solve my problem.. I tried ASIHTTPRequest but i faced some problems with setting up the Libraries. And if i’m not wrong, ASIHTTPRequest is not such a good idea in i-OS 5 (i m not sure about this).. Anyway, from this point can anyone please help me about how to parse the JSON above?
Finaly i figured out, i have done everything before, i just realized that..
for example when i tried:
NSString*key1=[ result objectForKey:@"key" ];
NSString *kAndVal=[result objectForKey:@"button"];
NSLog(@"\n%@ : %@", key1, kAndVal);
i got the key and button values above.. I hope this answer will save lots of newbies like me out of trouble..
You should parse your JSON anwer using a JSON parser. iOS 5 has its own JSON parser. In case you want to support iOS 4 check out JSONKIT https://github.com/johnezang/JSONKit