php - How can I parse this json schema in Objective-c -
i have ios app seek station , , add fuel price.
i found opendata database, can't parse array "fields" , "price_e10", array "records".
here's example of json schema (i think it's multidimensional-array):
"records":[ { "datasetid":"prix_des_carburants_j_7", "recordid":"fa74ca1fdf6938333d2bc1013623b66771557b31", "fields":{ "price_e10":1.389,
here example of code in objective-c :
nserror *e; nsdictionary *dict = [nsjsonserialization jsonobjectwithdata:responsedata options: nsjsonreadingmutablecontainers error: &e]; nsarray *arrayresult =[dict objectforkey:@"records"]; arraysmpl = [nsmutablearray arraywitharray:arrayresult]; nslog(@" multiple array : %@ ",arrayresult); rowsinsection = [arraysmpl count] + 1;
thanks help
i considered data coming server.
nsdictionary *globaldict = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves error:&error]; nsarray *recordsarray = [globaldict valueforkey:@"records"]; (nsdictionary *dict in recordsarray) { nsdictionary *fieldsdict = [dict valueforkey:@"fields"]; nsstring *fuelprice = [fieldsdict valueforkey:@"price_e10"]; nslog(@"fuelprice: %@", fuelprice); }
output : fuelprice: 1.389
Comments
Post a Comment