我试图解析下面的动态密钥Json String.
"report":{ "data":{ "results":{ "558952cca6d73d7d81c2eb9d":{ "Max":-1,"Min":-1,"Slope":-1,},"558ce148a6d73d7d81c2fa8a":{ "Max":-2,"Slope":-2,} } } }
以下我试图获取数据,但在解析最后一个动态json字符串时收到错误.
public class Report { @SerializedName("data") @Expose private Data data; public Data getData() { return data; } public void setData(Data data) { this.data = data; } @Override public String toString() { return "Report{" + "data=" + data + '}'; } } public class Data { @SerializedName("results") @Expose private ResultInside result; public ResultInside getResult() { return result; } public void setResult(ResultInside result) { this.result = result; } } public class ResultInside { /*@SerializedName("results") @Expose*/ private Map<String,Vitals> elemDetails = new HashMap<>(); public Map<String,Vitals> getElemDetails() { return elemDetails; } public void setElemDetails(Map<String,Vitals> elemDetails) { this.elemDetails = elemDetails; } }
任何建议如何解析在这种情况下!
解决方法
您的resultInside类添加了一个不存在于JSON中的额外的对象层.尝试将地图移动到您的数据类结果字段.
public class Data { @SerializedName("results") @Expose private Map<String,Vitals> result; //.... }