我正在尝试解析以下动态键Json String。
"report":{ "data":{ "results":{ "558952cca6d73d7d81c2eb9d":{ "Max":-1, "Min":-1, "Slope":-1, }, "558ce148a6d73d7d81c2fa8a":{ "Max":-2, "Min":-1, "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中不存在的额外对象层。尝试将地图移至您的Data班级results字段。
resultInside
Data
results
public class Data { @SerializedName("results") @Expose private Map<String, Vitals> result; //.... }