objective c - JSON array Parsing issue in iOS -
i've got json request i'm able add nsdictionary i'm unable access part of json string. here sample
{ "resp": { "success": "true", "who": { "userid": 234, }, "students": [ { "id": 1, "name": john }, { "id": 2, "name": jane } ], } }
i storing data in nsmutabledictionary , passing function should run through each student , process them accordingly.
here i've got far , it's not working:
-(void)foo:(nsmutabledictionary*)json { nsarray *students = json[@"students"]; for(nsmutabledictionary *student in students) { nslog(@"student id: %@", student[@"id"]); } }
when debugging can see json object , students belongs under resp value.
first of all, check json on validity http://jsonlint.com . corrected json next modifications:
{ "resp": { "success": "true", "who": { "userid": 234 }, "students": [ { "id": 1, "name": "john" }, { "id": 2, "name": "jane" } ] } }
then should access elements in right way:
- (void)foo:(nsmutabledictionary *)json { nsarray *students = json[@"resp"][@"students"]; for(nsdictionary *student in students) { nslog(@"student id: %@", student[@"id"]); } }
for should working.
Comments
Post a Comment