【发布时间】:2015-04-06 22:12:49
【问题描述】:
我的代码工作正常,但我似乎无法进入树的更深部分。我正在尝试拉经度和纬度。下面的代码将 'status' 拉为 'OK' 没问题(在响应的最后)。'geometry' -> 'location' -> 'lat' 和 'lng' 的语法是什么?
这是我的代码:
string RawAddress = "163 Leektown Road, New Gretna, NJ 08004";
string Address = RawAddress.Replace(" ", "+");
string AddressURL = "http://maps.google.com/maps/api/geocode/json?address=" + Address;
var result = new System.Net.WebClient().DownloadString(AddressURL);
dynamic data = JObject.Parse(result);
Lat.Text = data.status;
这是 API 生成的内容:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Mountain View",
"short_name" : "Mountain View",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Santa Clara County",
"short_name" : "Santa Clara County",
"types" : [ "administrative_area_level_2", "political" ]
},
{
"long_name" : "California",
"short_name" : "CA",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "United States",
"short_name" : "US",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Mountain View, CA, USA",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 37.4508789,
"lng" : -122.0446721
},
"southwest" : {
"lat" : 37.3567599,
"lng" : -122.1178619
}
},
"location" : {
"lat" : 37.3860517,
"lng" : -122.0838511
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 37.4508789,
"lng" : -122.0446721
},
"southwest" : {
"lat" : 37.3567599,
"lng" : -122.1178619
}
}
},
"partial_match" : true,
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
【问题讨论】:
-
How to parse json in C#? 的可能重复项
-
尝试将 Json 粘贴到此页面:json2csharp.com
-
MethodMan,谢谢。我已经看到了,但它没有帮助。聚会,因为我不知道我应该使用什么命名空间。我对我发布的内容很满意,因为它确实有效。
-
Lasse V. Karlsen,也谢谢你,但我无法理解它。如何将它们插入?