objective c - YELP 1.0 JSON access with NSDictionary -
i doing pretty parsing yelp1 json nsjsonserialization , accessing info nsdictionary. however, figured inconsistencies in response:
some keys surrounded "
, ones containing _
parts 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 documentation no keys in brackets. http://www.yelp.com/developers/documentation/search_api
aperently, brackets indicate '_' in key value reason, not type of value. brackets surround each key containing _
, may value string or int or whatever.
accessing fields such avg_rating with
[dict objectforkey:@"avg_rating"];
fails nsinvalidargumentexception
while [dict objectforkey:@"country"];
work.
hence, dont believe it's nsdictionary / nslog problem value returned, problem key submitted dict object. or, maybe during json parsing? please, prove me wrong piece of working code... :)
any ideas? thanks, el
edit: edited because question might have been clear enough. edit2: in fact, nsnumber returned here. got confused these "" .
parts response:
no. that's not part of response. that's description of resulting nsdictionary
not json.
nslog([dict objectforkey:@"avg_rating"]);
fails nsinvalidargumentexception
, while nslog([dict objectforkey:@"country"]);
work.
sure, because nslog()
ain't no magic. expects (format) string first argument, if object feed nsstring
, work fine (country
string, assume), if don't (avg_rating
may nsnumber
), won't (it seek send messages of nsstring
nsnumber
instance, fails).
so understand difference between json , description of nsdictionary
generated json.
objective-c ios6 nsjsonserialization yelp
No comments:
Post a Comment