Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I use the TouchJSON library available here</p> <p><a href="https://github.com/TouchCode/TouchJSON" rel="nofollow">https://github.com/TouchCode/TouchJSON</a></p> <p>to do something alone the lines of:</p> <pre><code>// For the purpose of this example, use stringWithContentsOfURL NSString *googleURL = @"http://maps.googleapis.com/maps/api/distancematrix/json?origins=Vancouver+BC|Seattle&amp;destinations=San+Francisco|Victoria+BC&amp;mode=bicycling&amp;language=fr-FR&amp;sensor=false"; NSURL *url = [NSURL URLWithString:[googleURL stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; NSError *error = NULL; NSString *theJSONString = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:&amp;error]; NSLog(@"%@", theJSONString); // Parse with TouchJSON NSDictionary *replyDict = [NSDictionary dictionaryWithJSONString:theJSONString error:&amp;error]; NSString *distanceString = [[[[[[replyDict objectForKey:@"rows"] objectAtIndex:0] objectForKey:@"elements"] objectAtIndex:0] objectForKey:@"distance"] objectForKey:@"value"]; double distance = distanceString.doubleValue; NSLog(@"Distance: %f", distance); NSLog(@"Error: [%@]", error.description); </code></pre> <p>and that gives me the following output on the console:</p> <pre><code>{ "destination_addresses" : [ "San Francisco, Californie, États-Unis", "Victoria, BC, Canada" ], "origin_addresses" : [ "Vancouver, BC, Canada", "Seattle, État de Washington, États-Unis" ], "rows" : [ { "elements" : [ { "distance" : { "text" : "1 686 km", "value" : 1685690 }, "duration" : { "text" : "3 jours 21 heures", "value" : 336418 }, "status" : "OK" }, { "distance" : { "text" : "136 km", "value" : 136478 }, "duration" : { "text" : "6 heures 59 minutes", "value" : 25117 }, "status" : "OK" } ] }, { "elements" : [ { "distance" : { "text" : "1 426 km", "value" : 1426087 }, "duration" : { "text" : "3 jours 6 heures", "value" : 281311 }, "status" : "OK" }, { "distance" : { "text" : "251 km", "value" : 251174 }, "duration" : { "text" : "12 heures 6 minutes", "value" : 43583 }, "status" : "OK" } ] } ], "status" : "OK" } Distance: 1685690.000000 Error: [(null)] </code></pre> <p>If you want to use SBJson instead you can get it here</p> <p><a href="https://github.com/stig/json-framework" rel="nofollow">https://github.com/stig/json-framework</a></p> <p>replace the line</p> <pre><code>// Parse with TouchJSON NSDictionary *replyDict = [NSDictionary dictionaryWithJSONString:theJSONString error:&amp;error]; </code></pre> <p>with </p> <pre><code>// Parse with SBJson SBJsonParser *parser = [[SBJsonParser alloc] init]; NSDictionary *replyDict = [parser objectWithString:theJSONString]; </code></pre> <p>Remember to include the relevant library in your .h file</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload