I have some json coming like the below, which i’m trying to turn into nsdictionaries. My problem is that the 1, 5 and 4 are keys, with unpredictable values. How would I get each object – {“id”:”A”,”name”:”Nike”} – without knowing the key?
// JSON looks like:
{
"shops":
{
"1":{"id":"A","name":"Nike"},
"5":{"id":"G","name":"Apple"}
"4":{"id":"I","name":"Target"}
}
}
// how to step thru this?
NSArray *shopsArray = [[shopsString JSONValue] objectForKey:@"shops"];
The returned object from
objectForKey:@"shops"is actually anNSDictionaryinstance, not anNSArray, since the keys are actually strings, not numeric values.For your purposes, you can simply call
-allValueson the resultingNSDictionary.EDIT: If you need ordering of the values, then you can do something like the following:
First, change the incoming JSON to this kind of structure:
Then, you can have ordering of the objects in the array.