问题描述
实际上我正在使用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 (将#修改为@)