I just successfully finished making my first JSON request and deserializing the information now all I need to do is know how to gather a few values from my dictionary. Here's what the request looks like:
@implementation ViewController {
GMSMapView *mapView_;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Make the URL connection in order to download JSON/XML data.
NSString *urlAsString = @"weburlgoeshere...";
NSURL *url = [NSURL URLWithString:urlAsString];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
// Error and 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 was downloaded");
}
else if (error != nil){
NSLog(@"Error happened = %@", error);
}
}];
}
This is what logs out to the 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 I stored all these values in an NSDictionary that I called "result" and I would like to know how to gather and store SPECIFIC key values for latitude and longitude in an NSNumber. I'm thinking that I might need to fastEnumerate most of these with a block, and then deal with the accordingly. The intent here is to use these values and display them onto a map. Any help would be greatly appreciated! Thank you!