我将尝试将一个对象反序列化为JSON格式,其中位置信息应该转换为GeoJSON格式。我尝试使用geojson.net NuGet包来实现这一点,但是我无法做到。目前在.NET中没有可用的GeoJSON示例。
public class Request
{
public int Id { get; set; }
public string Name { get; set; }
public Fence Fence { get; set; }
}
public class Fence
{
public int Type { get; set; }
public List<PValues> Values { get; set; }
}
public class PValues
{
public double Latitude { get; set; }
public double Longitude { get; set; }
}
我希望将Request对象转换为JSON。我可以使用Newtonsoft反序列化实现这一目标,但是Request PValues必须转换为geojson多边形类型。在C#中该如何实现?
我对GeoJson还不熟悉,但是当我阅读规范时,多边形规范如下:
{
"type": "FeatureCollection",
"features": [
{
"type": "Feature",
"properties": {},
"geometry": {
"type": "Polygon",
"coordinates": [
[
[80.227249, 12.901617],
[80.227764, 12.888553],
[80.232056, 12.89006],
[80.233086, 12.900779],
[80.227249, 12.901617]
]
]
}
}
]
}
所以,我需要在反序列化请求类时使用上述对象来代替值。