ios - Convert JSON feed to NSDictionary -
where json_category_data_url_string feed url, returns fine as:
[ { "group":"for sale", "code":"ssss" }, { "group":"for sale", "category":"wanted", "code":"swnt" } ] i cannot seem nice nsdictionary (or nsarray) out of following code:
+ (nsdictionary *)downloadjson { nsdictionary *json_string; nsstring *dataurl = [nsstring stringwithformat:@"%@", json_category_data_url_string]; nslog(@"%@",dataurl); nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:dataurl]]; nsdata *response = [nsurlconnection sendsynchronousrequest:request returningresponse:nil error:nil]; json_string = [[[nsstring alloc] initwithdata:response encoding:nsutf8stringencoding]autorelease]; nsdictionary *json_dict = (nsdictionary *)json_string; nslog(@"json_dict\n%@",json_dict); nslog(@"json_string\n%@",json_string); return json_string; } i've read many posts on this, not getting it.
with ios5 can use nsjsonserialization serializing json.
nsdictionary *dictionary = [nsjsonserialization jsonobjectwithdata:data options:kniloptions error:&error]; hope you.
Comments
Post a Comment