objective c - Converting Dictionary key values into NSNumber -


i finished making first json request , deserializing information need know how gather few values dictionary. here's request looks like:

@implementation viewcontroller {     gmsmapview *mapview_; }  - (void)viewdidload {     [super viewdidload];      // make url connection in order download json/xml data.     nsstring *urlasstring = @"weburlgoeshere...";     nsurl *url = [nsurl urlwithstring:urlasstring];     nsurlrequest *urlrequest = [nsurlrequest requestwithurl:url];     nsoperationqueue *queue = [[nsoperationqueue alloc] init];      // error , success message handling.     [nsurlconnection     sendasynchronousrequest:urlrequest     queue:queue      completionhandler:^(nsurlresponse *response, nsdata *data, nserror *error) {          if([data length] > 0 &&             error == nil){              nsdata *jsondata = [nsdata datawithcontentsofurl:url];               if (jsondata != nil){                  nserror *error = nil;                   nsdictionary *result = [nsjsonserialization jsonobjectwithdata:jsondata options:nsjsonreadingmutablecontainers error:&error];                  if(error == nil)                  nslog(@"%@", [result valueforkey:@"merchants"]);              }           }          else if ([data length] == 0 &&          error == nil){          nslog(@"nothing downloaded");           }          else if (error != nil){          nslog(@"error happened = %@", error);           }        }];  } 

this logs out console:

branches =         (                         {                 city = "......";                 country = "united states";                 countryisocode = usa;                 distanceinkms = "8.31";                 distanceinmiles = "5.16";                 id = 7952205;                 latitude = ".......";                 longitude = "........";                 name = ".......";                 state = ......;                 stateisocode = .....;                 street = ".........";                 telephone = "";             }         );         id = 174535;         logourl = ".......";         name = "......."; 

so stored these values in nsdictionary called "result" , know how gather , store specific key values latitude , longitude in nsnumber. i'm thinking might need fastenumerate of these block, , deal accordingly. intent here use these values , display them onto map. appreciated! thank you!

you can access required values keys in manner.

nsarray * array = [dic objectforkey:@"branches"]; nsdictionary *furthernames = array[0]; nsnumber *latitude = [nsnumber numberwithfloat:[[furthernames objectforkey:@"latitude"] floatvalue]]; nsnumber *longitude = [nsnumber numberwithfloat:[[furthernames objectforkey:@"longitude"] floatvalue]]; 

all need observe () => array of objects, {} => dictionary. hence traverse them accordingly.

hope helps.


Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -