【发布时间】:2017-01-03 12:41:12
【问题描述】:
我正在使用谷歌的地理编码 API 根据我传递的邮政编码获取数据,如下所示:
http://maps.googleapis.com/maps/api/geocode/json?address=97001&sensor=true
我得到这样的结果:
{
"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"
}
现在这很好,但我只想从“addres_component”中挑选类型等于的记录:
"types" : [ "administrative_area_level_1", "political" ]
我可以这样做来获取值:
JObject.Parse(myJson)["keyhere"].ToString();
但是我如何实际检查值 short_name 和 long_name 的类型是否是我在上面放置的类型?
如何使用 JObject 类实现这一点?
【问题讨论】:
标签: c# asp.net json asp.net-mvc geocode