Parsing Json in iOS without keys common -


my json string :

[     {'local':'webaddress'},     {'qa':'webaddress1'} ] 

my code :

nsmutabledictionary *datadictonary = [nsjsonserialization                                        jsonobjectwithdata:responsedata                                        options:0                                        error:nil];           nsarray *keys = [datadictonary allkeys];         nsarray *values = [datadictonary allvalues];         int i=0;         nslog(@"",[keys count]);         nslog(@"",[values count]);         int i=0;         ( nsstring *items in keys )         {             nslog(@"----");             nslog(@"name: %@", items);             nslog(@"address: %@", values[i++]);             nslog(@"----");         } 

here size nothing blank in nslog , can't parse value don't don't why. please help..

your json array objects inside need convert nsarray:

nsstring *json_string = @"[{\"local\": \"webaddress\" }, {\"qa\": \"webaddress1\" }]"; nserror *error; nsarray *json = [nsjsonserialization jsonobjectwithdata: [json_string datausingencoding:nsutf8stringencoding]                                 options: nsjsonreadingmutablecontainers                                   error: &error];  nslog(@"local: %@", json[0][@"local"]); // output is: local: webaddress 

update

// itherate through array for(nsdictionary *dictionary in json) {     //now can iterate throug each dicitonary     nsenumerator *enumerator = [dictionary keyenumerator];     id key;      while((key = [enumerator nextobject])){         nslog(@"key=%@ value=%@", key, [dictionary objectforkey:key]);     } } 

log looks this:

key=local value=webaddress

key=qa value=webaddress1


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -