解析使用改造动态密钥JSON字符串

解析使用改造动态密钥JSON字符串

本文介绍了解析使用改造动态密钥JSON字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图解析以下动态密钥JSON字符串。

I'm trying to parse following dynamic key Json String.

"report":{
    "data":{
        "results":{
            "558952cca6d73d7d81c2eb9d":{
                "Max":-1,
                "Min":-1,
                "Slope":-1,
            },

            "558ce148a6d73d7d81c2fa8a":{
                "Max":-2,
                "Min":-1,
                "Slope":-2,
            }
        }
    }
}

下面我试图获取数据,但得到错误,而去年解析动态JSON字符串。

Following I'm trying to get data, but getting error while parse last dynamic json String.

 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;
        }
    }

任何建议如何分析在这种情况下!

Any suggestion how to parse in this case !

推荐答案

resultInside 类并称不会在JSON存在一个额外的对象层。尝试将地图到您的数据结果字段。

Your resultInside class is adding an extra object layer that does not exist in your JSON. Try moving the map to your Data class results field.

public class Data {
    @SerializedName("results")
    @Expose
    private Map<String, Vitals> result;

    //....
}

这篇关于解析使用改造动态密钥JSON字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-02 18:06