getting two values from jobject from geocoding google maps api

Aug 16, 2010 at 2:05 AM
Edited Aug 16, 2010 at 2:08 AM

Hi,

 

I am new to json.net, and I am trying very simply to get two values from this json-generated code from Google Maps geocoding api:

 

{ "status": "OK", "results": [ 
{ "types": [ "street_address" ],
"formatted_address"
: "250 Queens Quay W, Toronto, ON M5J 2Y7, Canada",
"address_components": [
{ "long_name": "250", "short_name": "250", "types": [ "street_number" ] },
{ "long_name": "Queens Quay W", "short_name": "Queens Quay W", "types": [ "route" ] },
{ "long_name": "Toronto", "short_name": "Toronto", "types": [ "locality", "political" ] },
{ "long_name": "Toronto Division", "short_name": "Toronto Division", "types": [ "administrative_area_level_2", "political" ] },
{ "long_name": "Ontario", "short_name": "ON", "types": [ "administrative_area_level_1", "political" ] },
{ "long_name": "Canada", "short_name": "CA", "types": [ "country", "political" ] },
{ "long_name": "M5J 2Y7", "short_name": "M5J 2Y7", "types": [ "postal_code" ] } ],
"geometry"
: {
"location": { "lat": 43.6391212, "lng": -79.3853607 },
"location_type": "RANGE_INTERPOLATED", "viewport": {
"southwest": { "lat": 43.6359652, "lng": -79.3885059 },
"northeast"
: { "lat": 43.6422605, "lng": -79.3822106 } },
"bounds"
: {
"southwest": { "lat": 43.6391045, "lng": -79.3853607 },
"northeast"
: { "lat": 43.6391212, "lng": -79.3853558 } } } } ] }

 

to put very simply, all I want is to get the "lat" and "lnt" from "location"

 

Here is what I have so far:

 

string text = GetGeocodeResponse(txtInput.Text);
lblResponse.Text = text + "<br />";

JObject jobject = JObject.Parse(text);
//string name = 

if ((string)jobject.SelectToken("status") == "OK")
        lblResponse.Text = jobject.ToString();

 

Aug 16, 2010 at 2:55 AM

 

nevermind, i was able to get it using:

 

jobject.SelectToken("results[0].geometry.location.lat")
and

jobject.SelectToken("results[0].geometry.location.lng");

 

thanks!