我该如何在C#中反序列化包含某些对象的jsonarray并使用不同类型的geojson?

问题描述

实际上我正在使用json.net库。

有一个可以在图片中看到的json数组示例。

JsonArray with object with geojson which type is multpipolygon

The same JsonArray with object which type of geojson is polygon

我为反序列化所做的

    public class GeoData {

    [JsonProperty("place_id")]
    public long place_id { get; set; }
    [JsonProperty("licence")]
    public string licence { get; set; }
    [JsonProperty("osm_type")]
    public string osm_type { get; set; }
    [JsonProperty("osm_id")]
    public long osm_id { get; set; }
    [JsonProperty("boundingbox")]
    public string [] boundingbox { get; set; }
    [JsonProperty("lat")]
    public string lat { get; set; }
    [JsonProperty("lon")]
    public string lon { get; set; }
    [JsonProperty("display_name")]
    public string display_name { get; set; }
    [JsonProperty("importance")]
    public string importance { get; set; }
    [JsonProperty("icon")]
    public string icon { get; set; }
    [JsonProperty("geojson")]
    public GeoJson geojson { get; set; }
}

    public class GeoJson {

    [JsonProperty("type")]
    public string type { get; set; }
    [JsonProperty("coordinates")]
    public IList<IList<IList<double>>> coordinates { get; set; }
}


List<GeoData> geoDataList = JsonConvert.DeserializeObject<List<GeoData>>(jsonData);

这将起作用,但前提是我们具有多边形类型。 如果jsonarray的jsonobject与geojson的类型为Multipolygon,我应该将GeoJson类更改为此

    public class GeoJson {

    [JsonProperty("type")]
    public string type { get; set; }
    [JsonProperty("coordinates")]
    public IList<IList<IList<IList<double>>>> coordinates { get; set; }
}

问题是如何根据类型正确反序列化?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...