ios - Parsing JSON using SBJSON, issue -
i getting json response in predicted form. tree looks this:
{ "data":{ "img":"image":"http:\/\/testingpage.com\/images\/frog_320x480_23.jpg", "link":"http:\/\/google.com","verbose":"hi there"}, "figures":[ { "id":"16","type":"sailor","color":"1e90fffa","icon":"sailor"}, {"id":"32","type":"pilot","color":"32cd32bc","icon":"pilot"} ] } }
i using sbjson library. getting values with
nsstring *jsonstring = [[nsstring alloc] initwithdata:idata encoding:nsutf8stringencoding]; nsdictionary *results = [jsonstring jsonvalue];
and getting keys need with:
results objectforkey:@"keyname"]
so far good.
what happened getting response different provider , result different in it's nature:
[ { "tempvalues": { "temp1": 13.2, "temp2":11.1, "temp3":11.2, "temp4":13.4 }, "semipath":"pollution", "value":"axt" }, { "tempvalues": { "temp1":19.3, "temp2":12.1, "temp3":10.8, "temp4":13.1}, "semipath":"pollution", "value":"aut" } ]
i have 2 problems here:
i don't know how access these values in root, array. , array has no key can refer to. should approach kind of structure? if need temp1
of first object of tempvalues
in array.
whenever seek value using results objectforkey:@"keyname"]
sigabrt because results
recognised array
you u have create similar this.
-(void) retrievedata{ nsmutableurlrequest *request=[nsmutableurlrequest requestwithurl:[nsurl urlwithstring:@"yoururl"]]; [request sethttpmethod:@"get"]; [request setvalue:@"application/json;charset=utf-8" forhttpheaderfield:@"tempvalues"]; nserror *err; nsurlresponse *response; nsdata *responsedata = [nsurlconnection sendsynchronousrequest:request returningresponse:&response error:&err]; nsarray *jsonarray = [nsjsonserialization jsonobjectwithdata:responsedata options: nsjsonreadingmutablecontainers error: &err]; variable=[[jsonarray objectatindex:0]objectforkey:@"keyname"]; }
ios objective-c json xcode
No comments:
Post a Comment