我有一个叫做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空间敏感吗? –