objective c - how to fetch this json -


how can json fetched. has dynamic values in it. below json.

{  level1:    {   row1:   {   1: "on",   2: "on",   3: "on",   4: "on",   5: "on",   6: "on",   7: "on",   8: "on",   9: "on",   10: "on",   attr: {   total: "10",    type: "gold"    }    },    row2: {    1: "on",    2: "on",    3: "on",    4: "on",    5: "on",   6: "on",    7: "on",   8: "on",   9: "on",   10: "on",   attr: {   total: "10",   type: "gold"   }   }   },   level3: {  row1: {  1: "on",  2: "on",  3: "on",  4: "on",  5: "on",  6: "on",  7: "on",  8: "on",   9: "on",  10: "on",  attr: {  total: "10",  type: "silver"  }  }  }  } 

in number of levels, number of rows dynamic , inside seats dynamic , how tackle not getting it. please guide above, have spend day on it. below code had tried yet.

  arrlevels = [self.mgetdatadict allkeys];          // getting levels here in array   nslog(@"keys:%@", arrlevels);    for(int i=0; i<[arrlevels count]; i++)       // trying rows in array   {     receivedatadict = [self.mgetdatadict valueforkey:[arrlevels objectatindex:i]];     [arrrows addobject:[nsstring stringwithformat:@"%d", [receivedatadict count]]];     nslog(@"data:%@", receivedatadict);     for(int j=0; j<[receivedatadict count]; j++)     {         nslog(@"count:%d", [receivedatadict count]);         dictrow = [receivedatadict valueforkey:@"attr"];         [arrtot addobject:[dictrow valueforkey:@"total"]];         [arrtype addobject:[dictrow valueforkey:@"type"]];     }  } 

step 1: download json framework ios here, , add library files project

step 2: import #import "json.h" in .h file

step 3: json data server or local.

nsdata *data = ...your json data...; nsstring *responsestring = [[nsstring alloc] initwithbytes:[data bytes] length:[data length] encoding:nsutf8stringencoding];  // parse using sbjson nsdictionary *dictresults = [nsdictionary dictionarywithdictionary:[responsestring jsonvalue]];  // read levels for(nsstring *key in [dictresults allkeys]) {     nslog(@"accessing .... %@",key);     for(nsstring *rowkey in dictresults[key])     {         nslog(@"%@",rowkey);         for(nsstring *valuekey in dictresults[key][rowkey])         {             nslog(@"%@ -> %@",valuekey,dictresults[key][rowkey][valuekey]);         }         nslog(@"--------row over------------\n");                 }     nslog(@"--------------------\n"); } 

Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -