How can I parse the JSON string output from HTTP POST in iOS -


i send parameters using post method server , there got response , store in string "serverresponse" .this server response stored in string

{      "caridentifier":[         {"carid":"91"},         {"carid":"93"},         {"carid":"114"},         {"carid":"117"}     ] } 

i have separate json parsing code,but dont know how can give input json parsing codes. following json parsing code

-(void)getcarlist:(nsstring *)serverresponse {      dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{         nsobject *recommendedcarjson = nil;         nsdata *recommendedcarsdata = [nsdata datawithcontentsofurl:[nsurl urlwithstring:serverresponse]];         nslog(@"%@",recommendedcarsdata);         if(recommendedcarsdata)             recommendedcarjson = [nsjsonserialization jsonobjectwithdata:recommendedbooksdata options:nsjsonreadingmutablecontainers error:nil];          if(!recommendedcarsdata){             nslog(@"error json serialization");         } else{             [self saverecommendedcardata:(nsdictionary *)recommendedcarjson];         }     } ); } 

in saverecommendedcardata method creating 1 plist , saving parsed data. how can give server response string input json parsing ??

nserror *jsonerror = nil; id allvalues = [nsjsonserialization jsonobjectwithdata:[serverresponse datausingencoding:nsutf8stringencoding]                                                options:0                                                  error:&jsonerror];  if(jsonerror!=nil)     nslog(@"json_err: %@",jsonerror);  nsarray *caridentifier = [(nsdictionary*)allvalues objectforkey:@"caridentifier"]; nslog(@"%@",caridentifier);  for(nsdictionary *dict in caridentifier)         nslog(@"carid: %@",[dict valueforkey:@"carid"]); 

try this.

update

-(void)getcarlist:(nsstring *)serverresponse {      dispatch_async(dispatch_get_global_queue(dispatch_queue_priority_high, 0), ^{         nserror *jsonerror = nil;         id allvalues = [nsjsonserialization jsonobjectwithdata:[serverresponse datausingencoding:nsutf8stringencoding]                                                    options:0                                                      error:&jsonerror];          if(jsonerror!=nil)             nslog(@"json_err: %@",jsonerror);          nsarray *caridentifier = [(nsdictionary*)allvalues objectforkey:@"caridentifier"];         nslog(@"%@",caridentifier);          for(nsdictionary *dict in caridentifier)                 nslog(@"carid: %@",[dict valueforkey:@"carid"]);          } ); } 

Comments

Popular posts from this blog

monitor web browser programmatically in Android? -

Shrink a YouTube video to responsive width -

wpf - PdfWriter.GetInstance throws System.NullReferenceException -