I have a very simple C# program that makes a URL call and retrieves a jSON string. This works fine.
static void Main(string[] args)
{
using (var webClient = new System.Net.WebClient())
{
var json = webClient.DownloadString("http://maps.google.com/maps/api/geocode/json?address=Oak%20Openings%20Metro%20Park%20Ohio&sensor=false);
var obj = JObject.Parse(json);
}
}
The JSON returned looks as follows:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Oak Openings Preserve Metropark",
"short_name" : "Oak Openings Preserve Metropark",
"types" : [ "establishment" ]
},
{
"long_name" : "Girdham Road",
"short_name" : "Girdham Rd",
"types" : [ "route" ]
},
{
"long_name" : "Swanton",
"short_name" : "Swanton",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Ohio",
"short_name" : "OH",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "43558",
"short_name" : "43558",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Oak Openings Preserve Metropark, Girdham Road, Swanton, OH 43558, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 41.5828434,
"lng" : -83.82480509999999
},
"southwest" : {
"lat" : 41.5286092,
"lng" : -83.8826873
}
},
"location" : {
"lat" : 41.5517744,
"lng" : -83.85260359999999
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 41.5828434,
"lng" : -83.82480509999999
},
"southwest" : {
"lat" : 41.5286092,
"lng" : -83.8826873
}
}
},
"partial_match" : true,
"types" : [ "park", "establishment" ]
},
{
"address_components" : [
{
"long_name" : "Oak Openings Metropark Lodge",
"short_name" : "Oak Openings Metropark Lodge",
"types" : [ "point_of_interest", "establishment" ]
},
{
"long_name" : "5230",
"short_name" : "5230",
"types" : [ "street_number" ]
},
{
"long_name" : "Wilkins Road",
"short_name" : "Wilkins Rd",
"types" : [ "route" ]
},
{
"long_name" : "Whitehouse",
"short_name" : "Whitehouse",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Swanton",
"short_name" : "Swanton",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Lucas County",
"short_name" : "Lucas County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "Ohio",
"short_name" : "OH",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
},
{
"long_name" : "43571",
"short_name" : "43571",
"types" : [ "postal_code" ]
}
],
"formatted_address" : "Oak Openings Metropark Lodge, 5230 Wilkins Road, Whitehouse, OH 43571, USA",
"geometry" : {
"location" : {
"lat" : 41.5483617,
"lng" : -83.8395838
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 41.5497106802915,
"lng" : -83.83823481970849
},
"southwest" : {
"lat" : 41.5470127197085,
"lng" : -83.84093278029151
}
}
},
"partial_match" : true,
"types" : [ "park", "point_of_interest", "establishment" ]
}
],
"status" : "OK"
}
I am very new to JSON, I would like to extract the lat and lng values from this piece:
"location": {
"lat": 27.9094665,
"lng": -82.7873244
},
but really have no idea how to go about it after I've called JObject.Parse.