I am retrieving json data from a url. The json "string" has one object that contains multiple objects inside of it, each of of the objects containing their own key, value properties...essentially the json object is an NSArray containing objects that are more or less dictionary objects. I'm trying to use NSJSONSerialization but there isn't a lot of documentation on it, and I can't seem to figure out how to Here is an example of what the json might look like:
{"allObjects":[{"firstName":"homer","middleName":"j","lastName":"simpson"
,"address": "123 evergreen terrace","countryCode":"US","zip":12345},
{"firstName": "marge","middleName":"b","lastName":"simpson","address":
"123 evergreen terrace","countryCode":"US","zip":12345}]}
(If it matters, the JSON object contains MANY more entries)
Are there specific "options" I need to use with NSJSONSerialization to get an array of dictionaries out (the array being "allObjects")?
Any help would be greatly appreciated!
Thanks in advance.
UPDATE
This code results in an error:
@vishy I thought this too, but when I run this code,
NSArray *json = [NSJSONSerialization JSONObjectWithData:geoNamesJSON options: kNilOptions error:&error];
NSDictionary *dict = [json objectAtIndex:0];
NSArray *allKeys = [dict allKeys];
NSString *key = [[NSString alloc] init];
NSEnumerator *keyEnum = [allKeys objectEnumerator];
NSLog(@"All keys in the first dictionary object:");
while(key = [keyEnum nextObject]){
NSLog(@"%@", key);}
I get this error:
-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x1fd7cd10 * Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFDictionary objectAtIndex:]: unrecognized selector sent to instance 0x1fd7cd10' * First throw call stack: (0x3796c2a3 0x35c7c97f 0x3796fe07 0x3796e531 0x378c5f68 0xf310b 0xf219d 0x38ca4321 0x38cdecfd 0x38d53cc1 0x38cd86a7 0x38cd8481 0x38c52abb 0x38cc78d7 0x355b9bd9 0x3665c4b7 0x366611bd 0x3793ff3b 0x378b2ebd 0x378b2d49 0x37def2eb 0x38c91301 0xd3551 0x3c39db20) libc++abi.dylib: terminate called throwing an exception (lldb)