I have a certain json:
[
{
"id" : 42422422,
"created" : 1329684013,
"name" : "Test"
},
{
"id" : 42422423,
"created" : 1329684015,
"name" : "Test 123"
},
{
...
}
]
Parsing this goed OK, but when the webserver has an error, this JSON is returned:
{
"error" : {
"code" : "511",
"message" : "JSON error",
"extra" : {
"some" : "text",
"someextra" : "text"
}
}
}
I’ve tried using this:
if ([jsonArray valueForKey:@"error"] != nil) {
but that doesn’t work, because if I output the value of that it’s an array of ‘null’s’
How can I check this? (I know I can use NSRange, but I think there has to be a better way right?
I parse the JSON like this:
NSDictionary *jsonArray = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error: &e];
responseData comes from the connectionDidFinishLoading method of NSURLConnection.
You should check if your result is an array or a dictionary first.