I am struggling with the following problem:
I’ve got an API which returns a nested JSON piece.
(I use NSJSONSeralization to parse it)
eg:
{ "thing" = 1,
"Other thing" = 2,
"ParentFromList": [{
"IT" = 3,
"SecondIT" = 4
}
How can I use IT and Second it?
I’ve tried:
NSDictionary *thingy = [[jsonOutput objectForKey:@"ParentFromList"] ObjectForKey:@"IT"];
JsonOutput is also a nsdictionary.
But after running it, it fails with:
Unrecognized Selector send to instance.
I don’t know how to fix this, help appreciated.
For your data, the outmost object is a
NSDictionaryinstance. The value for the key ParentFromList is an array, i.e. aNSArrayinstance (note the brackets). The arrays first element contains another dictionary instance (note the curly braces).Furthermore, it’s not
ObjectForKey:butobjectForKey:(case matters).So you probably want to write:
BTW: Your sample JSON data is both incomplete and not in JSON format (it’s Apple’s property list format).
The correct and complete JSON representation would be: