ios - How To Get Particular Values From JSON and Plot on Map view Using Objective C? -
i need particular values below json
response, values have mentioned below
reg no: (need show callout) lat : (need use drop pin on map) long : (need use drop pin on map) name : (need show callout) age : (need show callout)
note :
school of array values getting server increase based on , b , c categories. not static!
{ = { school = ( { reg_no = 1; latitude = "22.345"; longitude = "-12.4567"; student = ( { name = "akila"; age = "23"; } ); city = "<null>"; state = tn; }, { reg_no = 2; latitude = "22.345"; longitude = "-12.4567"; student = ( { name = "sam"; age = "23"; } ); city = "<null>"; state = tn; }, { reg_no = 3; latitude = "22.345"; longitude = "-12.4567"; student = ( { name = "lansi"; age = "23"; } ); city = "<null>"; state = tn; } ); schoolname = "good school"; categories = school; }; }
my code (below code not working) :
if (data) { nserror *error; nsdictionary *json = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves | nsjsonreadingmutablecontainers error:&error]; nsdictionary *response = json[@"response"]; (nsdictionary *entry in response[@"a"][@"school"]) { nsstring *regno = entry[@"reg_no"]; nsstring *name = entry[@"student"][@"name"]; nsstring *age = entry[@"student"][@"age"]; double latitude = [entry[@"latitude"] doublevalue]; double longitude = [entry[@"longitude"] doublevalue]; mkpointannotation *myannotation = [[mkpointannotation alloc] init]; myannotation.coordinate = cllocationcoordinate2dmake(latitude, longitude); myannotation.title = name; myannotation.subtitle = [nsstring stringwithformat:@"reg: %@, age: %@", regno, age]; [mapview addannotation:myannotation]; }
try nsjsonserialization
nserror *e = nil; nsarray *jsonarray = [nsjsonserialization jsonobjectwithdata: data options: nsjsonreadingmutablecontainers error: &e]; if (!jsonarray) { nslog(@"error parsing json: %@", e); } else { for(nsdictionary *item in jsonarray) { nslog(@"item: %@", item); } }
Comments
Post a Comment