In my application I catch the response from server in json format, something like this:
{"hotels":
{"data":
[{"id":"id1",
"country":"counry1",
"state":"state1",
"city":"city1",
}
{"id":"id2",
"country":"counry2",
"state":"state2",
"city":"city2",
}]
}
}
If I try to access to element by this code
ID = [[[ParsedResponse objectForKey:@"hotels"] objectForKey:@"data"] valueForKey:@"id"];
everything is ok. But if I do
NSMutableDictionary *ItemsFromParsedResponse = [[NSMutableDictionary alloc] init];
ItemsFromParsedResponse = [ParsedResponse valueForKeyPath:@"hotels.data"];
while (ItemsFromParsedResponse = (NSMutableDictionary*)[ParsedResponseEnumerator nextObject]) {
ID = [ItemsFromParsedResponse valueForKey:@"id"];
}
ID is [null]. And I don’t understand, why.
Thanks for any advice.
You’re either doing something strange here, or we don’t have all your code. I would write your failing piece of code as follows:
I’ve followed the convention of variable names beginning with a lowercase character (starting with an uppercase character should be reserved for class names), and I’m using fast enumeration, bearing in mind that the information at
hotels.datais anNSArray. I’ve also renamedIDtojsonIDto avoid confusion with theidpointer.