objective c - Iterate through JSON array (App Crashing) -
i trying iterate trough json array both item key , value.
this json array:
{ "clientdata": [{ "name": "michael" }, { "last": "ortiz" }, { "phone": "5555555555" }, { "email": "test@gmail.com" }], "clientaccess": [{ "t-shirt": "yes" }, { "meals": "no" }, { "vip": "yes" }, { "registration completed": "pending" }] } now, trying iterate through "clientdata" array, reason app crashing exception:
*** terminating app due uncaught exception 'nsinvalidargumentexception', reason: '-[__nscfstring objectforkey:]: unrecognized selector sent instance this code using iterate through json array:
nsdictionary* object = [nsjsonserialization jsonobjectwithdata:jsondata options:kniloptions error:nil]; // client profile data nsdictionary *clientdatadict = [object objectforkey:@"clientdata"]; (id item in clientdatadict) { [jsonuserdata addobject:[clientdatadict objectforkey:item]]; } this code working fine when didn't have each item on json array placed inside array. did keep consecutive order on array.
can give me pointers on problem is?
thank you!
clientdata array – represented square brackets [] – containing dictionaries 1 key/value pair respectively (a quite cumbersome structure).
nsdictionary* object = [nsjsonserialization jsonobjectwithdata:jsondata options:kniloptions error:nil]; // client profile data nsarray *clientdataarray = [object objectforkey:@"clientdata"]; (nsdictionary *dict in clientdataarray) { (nsstring *key in dict) { [jsonuserdata addobject:[dict objectforkey:key]]; } }
Comments
Post a Comment