如何解决我该如何在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 举报,一经查实,本站将立刻删除。