我有一個叫做LatLong
的類,它存儲兩個strings
,latitude
和longitude
。我有一個名爲LatLongs
另一類是類型的列表LatLong
C#JsonConvert.DeserializeObject填充列表爲空
public class LatLongs
{
public List<LatLong> latlongs { get; set; }
public string location_name { get; set; }
}
public class LatLong
{
public string latitude { get; set; }
public string longitude { get; set; }
}
最後我還有一個叫Locations
類,它擁有JSON
串稱爲geofence_coordinates
的JSON字符串中有兩個字段,latitude
和longitude
,是用於將這些值存儲在SQL服務器上。 JSON字符串如下所示:
[
{
" latitude ":"-34.95771393255739",
" longitude ":"138.46961975097656"
},
{
" latitude ":"-34.9520861634788",
" longitude ":"138.57330322265625"
},
{
" latitude ":"-35.00947127349485",
" longitude ":"138.50017547607422"
},
{
" latitude ":"-35.00806525651258",
" longitude ":"138.57467651367188"
}
]
下面是我的代碼無法正常工作的地方。我有一個名爲Locations
的列表,名爲coords
。我創建了一個我打算用我的JSON座標來填充,但此刻的JSON不能正常工作,它是被送入null
List<Locations> coords = await locationTable.Where(u => u.fk_company_id == viewModel.UserData.fk_company_id).ToListAsync();
List<LatLongs> latLongs = coords.Select(c => new LatLongs
{
latlongs = JsonConvert.DeserializeObject<List<LatLong>>(c.geofence_coordinates)
}).ToList();
我是用JsonConvert.DeserializeObject
錯了嗎?
那些JSON屬性名稱的開頭和結尾是否真的有空格?例如。 ''緯度「'開始並以空格結束。 – dbc
這是完整的json嗎?包裝對象在哪裏呈現? –
@dbc是JSON空間敏感嗎? –