我正在从一个空气质量网站反序列化 Json,该网站具有纬度和经度数组。 Json 看起来像这样:
{
"geo": [
-36.05035,
146.942
],
"name": "Albury South-west Slopes, Australia",
"url": "https://aqicn.org/city/australia/nsw/albury/south-west-slopes"
}
我编写了一个自定义反序列化器来完成这项工作,但我无法反序列化 "geo": [-36.05035, 146.942]
。
我的代码如下所示:
public static class City {
private Geo[] geo;
private String name;
private String url;
public Geo[] getGeo() {
return geo;
}
public void setGeo(Geo[] geo) {
this.geo = geo;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
public static class Geo {
//what are the getters and setters for an array with no names just numbers?
}
把我难住了 谢谢菲尔
最佳答案
您可以将 Jackson 与自定义解串器一起使用。作为引用,您可以查看Custom deserializer
关于arrays - Gson 我无法反序列化包含纬度和经度的数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59807040/