Is the following statement correct, or am I missing something?
You should check the returned NSJSONSerialization object to see if it is a dictionary or an array - you can have
data = {"name":"joe", "age":"young"}
and
data = {{"name":"joe", "age":"young"}, {"name":"fred", "age":"not so young"}}
Each type has a different access method that breaks if used incorrectly. For example:
NSMutableArray *jsonObject = [json objectAtIndex:i];
so you need to do something like -
id jsonObjects = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error]; if ([jsonObjects isKindOfClass:[NSArray class]]) NSLog(@"yes we got an Array");
I had a good look through the stack overflow, Apple documentation and other places, and I could not find direct confirmation above.
user1705452
source share