I use the google geocoding API to retrieve data based on a zip code, which I pass as follows:
http://maps.googleapis.com/maps/api/geocode/json?address=97001&sensor=true
I get this result:
{
"results" : [
{
"address_components" : [
{
"long_name" : "97001",
"short_name" : "97001",
"types" : [ "postal_code" ]
},
{
"long_name" : "Antelope",
"short_name" : "Antelope",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Oregon",
"short_name" : "OR",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Antelope, OR 97001, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 45.0835979,
"lng" : -120.476616
},
"southwest" : {
"lat" : 44.801399,
"lng" : -120.91835
}
},
"location" : {
"lat" : 44.9552895,
"lng" : -120.6265837
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 45.0835979,
"lng" : -120.476616
},
"southwest" : {
"lat" : 44.801399,
"lng" : -120.91835
}
}
},
"place_id" : "ChIJhZMDGc0ovFQRBev1yy22nAk",
"types" : [ "postal_code" ]
}
],
"status" : "OK"
}
Now this is good, but I would like to select only the entry from "addres_component", where the types are equal:
"types" : [ "administrative_area_level_1", "political" ]
I can do something like this to get the value:
JObject.Parse(myJson)["keyhere"].ToString();
But how do I really check if the type for the short_name and long_name values is what I set above?
How can I achieve this with the JObject class?