I was doing pretty good parsing YELP1 Json with NSJSONSerialization and accessing the data with NSDictionary. However, I figured inconsistencies in the response:
Some keys are surrounded with "
, mostly the ones containing a _
Parts from the response:
(
{
address1 = "xxx";
address2 = "";
address3 = "";
"avg_rating" = 5;
city = "Chicago";
country = USA;
"country_code" = US;
Obtained from
[[NSString alloc] initWithData:self.recievedData encoding:NSUTF8StringEncoding];
That's inconsistent to the documentation where no keys are in brackets. http://www.yelp.com/developers/documentation/search_api
Aperently, the brackets indicate the '_' in the key value for some reason, not the type of the value. Brackets surround each key containing _
, may the value be a string or a int or whatever.
Accessing fields such as avg_rating with
[dict objectForKey:@"avg_rating"];
fails with NSInvalidArgumentException
while [dict objectForKey:@"country"];
would work.
Hence, I dont believe it's a NSDictionary / NSLog problem with the value returned, but a problem with the key submitted to the dict object. Or, maybe during the JSON parsing? But please, prove me wrong with piece of working code... :)
Any ideas? Thanks, el
Edit: edited because question might now have been clear enough.
Edit2:
In fact, it was that a NSNumber is returned here. Got confused about these "" .