ios - Parse JSON to get value for key -


i trying retrieve value json not getting it. seems have difference between response in json , key. can suggest how this?

 nsdictionary *jsonresults = [nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutablecontainers error:nil];             nslog(@"results: %@", jsonresults);  /* logs console follows: results: {     code = 200;     error = "<null>";     response =     {         "insert_id" = 3861;     };         nslog(@"insert_id%@",[jsonresults objectforkey:@"insert_id"]); //this logs  insert_id (null) 

look @ output of jsonresults. curly braces indicate dictionary. , note value of "response" key. value has further curly braces. means nested dictionary.

the "insert_id" key nested inside "response" key's dictionary. need:

nslog(@"insert_id%@",jsonresults[@"response"][@"insert_id"]); 

also note use of modern syntax. it's easier read , write.


Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -