1

我想用我的扩展反序列化 GeoJSON。

GeoJSON 的线坐标为

{ coordinates: [[longitude1, latitude1], [longitude2, latitude2, optional_altitude2]] }

这可以扩展到高度之外。所以以下是 LineString 的有效 GeoJSON 坐标

{ coordinates: [[longitude1, latitude1], [longitude2, latitude2, optional_altitude2, { my_extension: something_something}]] }

所以,我定义我的类如下:

public class GeoJSonCooridnateExtension
{

    /// <summary>Gets type - should be "Feature".</summary>
    [DataMember(Name = "Something", IsRequired = true)]
    public string Something { get; internal set; }
}

public class GeoJSonGeometry
{
    /// <summary>Gets type - should be "Feature".</summary>
    [DataMember(Name = "type", Order = 0, IsRequired = true)]
    public string GeometryType { get; internal set; }

    /// <summary>Gets horizontal (west-east) position.</summary>
    [DataMember(Name = "coordinates", Order = 1, IsRequired = true)]
    public List<List<object>> Coordinates { get; internal set; }
}

创建序列化程序时,我将“GeoJSonCooridnateExtension”作为“已知类型”传递。反序列化器成功,但将一个通用对象放入数组中,而不是我创建的类型。我尝试使用对象 API 来查询通用对象属性,但没有返回。甚至可以用 DataContractJSonSerializer 做到这一点吗?

请参阅下面的示例 JSON:

{
    "type": "Feature",        
    "geometry":
    {
        "type": "LineString",          
        "coordinates":             
        [
            [-35.480741083326052,47.926613991573959, null, {"Something":"my-value"}],
            [-34.355741083326052,58.027854137187823],
            [-27.605741083326055,49.776973283701281]
        ]           
    }
}
4

0 回答 0