I have a certain json:
[
{
\"id\" : 42422422,
\"created\" : 1329684013,
\"name\" : \"Test\"
},
{
With your non-error JSON payload you have a top level Array (noted by the beginning [ ), whilst with your error JSON payload you don't.
{
"error" : {
"code" : "511",
"message" : "JSON error",
"extra" : {
"some" : "text",
"someextra" : "text"
}
}
}
The error code is a nested dictionary object, therefore you would use the following to parse it:
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:responseData
options:kNilOptions
error:&error];
NSString *errorCode = [NSString stringWithFormat:@"%@",[(NSDictionary*)[json objectForKey:@"error"]objectForKey:@"code"]];