I have the following json returned string:
[{"status":2,"id":"-1","content":"User has entered wrong input","time":1346765646202}]
(as you can see the result is in an array that contains a single object).
How can I extract the value of status and content without Enumeration?
For now I created a dictionary and run on it with enumeration, but I don’t like the solution:
NSData *jsonData = [returnString dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:&error];
Because the whole thing is wrapped in [], it will deserialize into an NSArray (of size 1) (not an NSDictionary as your code implies). The element in that array will be an NSDictionary (
{}). You can get that dictionary withobjectAtIndex:0and skip your enumeration: