0
我已經使用json2csharp生成類。 有都好於var content = response.Content;
我也反序列化的主類:複雜的反序列化json與嵌套類c#
var responseData1 = JsonConvert.DeserializeObject<RootObjectChangeLocation>(content);
但我需要檢索緯度和經度從這個類:
public class Location
{
public double lat { get; set; }
public double lng { get; set; }
}
我試圖讓var responseData1 = JsonConvert.DeserializeObject<Location>(content);
檢索座標。但是,如果我直接執行,則lat
和lng
在responseData1
中爲空。我怎樣才能得到它們? 這是由json2csharp生成的代碼:
public class AddressComponent
{
public string long_name { get; set; }
public string short_name { get; set; }
public List<string> types { get; set; }
}
public class Northeast
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Southwest
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Bounds
{
public Northeast northeast { get; set; }
public Southwest southwest { get; set; }
}
public class Location
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Northeast2
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Southwest2
{
public double lat { get; set; }
public double lng { get; set; }
}
public class Viewport
{
public Northeast2 northeast { get; set; }
public Southwest2 southwest { get; set; }
}
public class Geometry
{
public Bounds bounds { get; set; }
public Location location { get; set; }
public string location_type { get; set; }
public Viewport viewport { get; set; }
}
public class Result
{
public List<AddressComponent> address_components { get; set; }
public string formatted_address { get; set; }
public Geometry geometry { get; set; }
public string place_id { get; set; }
public List<string> types { get; set; }
}
public class RootObjectChangeLocation
{
public List<Result> results { get; set; }
public string status { get; set; }
}
的jsonString是:
{
"results" : [
{
"address_components" : [
{
"long_name" : "Vinnytsia",
"short_name" : "Vinnytsia",
"types" : [ "locality", "political" ]
},
{
"long_name" : "Vinnyts'ka city council",
"short_name" : "Vinnyts'ka city council",
"types" : [ "administrative_area_level_3", "political" ]
},
{
"long_name" : "Vinnyts'ka oblast",
"short_name" : "Vinnyts'ka oblast",
"types" : [ "administrative_area_level_1", "political" ]
},
{
"long_name" : "Ukraine",
"short_name" : "UA",
"types" : [ "country", "political" ]
}
],
"formatted_address" : "Vinnytsia, Vinnyts'ka oblast, Ukraine",
"geometry" : {
"bounds" : {
"northeast" : {
"lat" : 49.27902,
"lng" : 28.5710879
},
"southwest" : {
"lat" : 49.190448,
"lng" : 28.3681799
}
},
"location" : {
"lat" : 49.233083,
"lng" : 28.468217
},
"location_type" : "APPROXIMATE",
"viewport" : {
"northeast" : {
"lat" : 49.27902,
"lng" : 28.5710879
},
"southwest" : {
"lat" : 49.1906116,
"lng" : 28.3681799
}
}
},
"place_id" : "ChIJiWRaGWVbLUcR_nTd7lnh1Ms",
"types" : [ "locality", "political" ]
}
],
"status" : "OK"
}
因此,要找到解決方案......是什麼問題? –
*我需要添加更多的細節來發布這個問題... * - 然後請在提問之前這樣做。你在找這個嗎? [Google地理編碼Json解析C#中的問題](https://stackoverflow.com/q/28371365/3744182)。 – dbc
請分享您嘗試解碼的JSON。 – dbc