this is a fairly simple question.
I am using a web service in my app, and the server returns a JSON string to communitcate with the app.
Here is an example response:
{
repsonse = {
message = "Message";
"response_id" = X;
};
}
Using objective-c I want to be able to get what "response_id" is but I am unsure on how to do this.
Here is my code:
NSMutableArray *json = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
// Get json value
NSLog(@"%@", json);
if([json[@"response"][@"response_id"] isEqualToString:@"1"]){
return YES;
}else{
return NO;
}
Each time the isStringEqualTo method returns false.
Could somebody help me?
Thanks,
Peter
You have two problems:
json
needs to be declared as an NSDictionary
, not NSMutableArray
since the JSON root is a dictionary, not an array. And you get back an immutable dictionary, not a mutable one.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.