如何使用相同的密钥处理JSON响应"值"它的字符串和带有Retrofit的数组

时间:2016-09-16 10:07:30

标签: java android json performance retrofit2

在JSON Response中有关键" Value"但它的响应有多种形式,如String和Array,具有相同的键" Value"。

那么如何让Retrofit模型类用相同的键维护String和Array" Value"。

    {
    "RespCode":"SUCCESS",
    "RespText":"Transaction Details",
       "Data":{
              "Record":[
               {
                  "group_title":"Seller Information",
                  "group_values":[
                   {
                        "key":"Listing Agent",
                        "value":[
                            {
                               "key":"Agent First Name",
                               "value":"Myks"
                            },
                            {
                                "key":"Agent Last Name",
                                "value":"Joe"
                            },
                            {
                                "key":"Company",
                                "value":"bdfjdlfdf"
                            },
                            {
                                "key":"Phone",
                                "value":"712.336.4967"
                            },
                            {
                                "key":"Email",
                                "value":"abc@gmail.com"
                            }
                        ]
                    },
                    {
                        "key":"Cell Phone",
                        "value":"012.345.6789"
                    },
                    {
                        "key":"Email",
                        "value":"balt@gmail.com.com"
                    },
                    {
                        "key":"Preferred Contact Method",
                        "value":"Phone"
                    }
                ]
            },
   ]
  }
}

2 个答案:

答案 0 :(得分:0)

只使用包含多个哈希映射的arraylist吗?或者......你必须定义一个pojo,它包含带有类型map的数组列表或者那种效果

答案 1 :(得分:0)

检查一下:

public  class ModelBean {

    private String RespCode;
    private String RespText;
    private DataBean Data;

    public String getRespCode() {
        return RespCode;
    }

    public void setRespCode(String RespCode) {
        this.RespCode = RespCode;
    }

    public String getRespText() {
        return RespText;
    }

    public void setRespText(String RespText) {
        this.RespText = RespText;
    }

    public DataBean getData() {
        return Data;
    }

    public void setData(DataBean Data) {
        this.Data = Data;
    }

    public static class DataBean {
        private List<RecordBean> Record;

        public List<RecordBean> getRecord() {
            return Record;
        }

        public void setRecord(List<RecordBean> Record) {
            this.Record = Record;
        }

        public static class RecordBean {
            private String group_title;
            private List<GroupValuesBean> group_values;

            public String getGroup_title() {
                return group_title;
            }

            public void setGroup_title(String group_title) {
                this.group_title = group_title;
            }

            public List<GroupValuesBean> getGroup_values() {
                return group_values;
            }

            public void setGroup_values(List<GroupValuesBean> group_values) {
                this.group_values = group_values;
            }

            public static class GroupValuesBean {
                private String key;
                private List<ValueBean> value;

                public String getKey() {
                    return key;
                }

                public void setKey(String key) {
                    this.key = key;
                }

                public List<ValueBean> getValue() {
                    return value;
                }

                public void setValue(List<ValueBean> value) {
                    this.value = value;
                }

                public static class ValueBean {
                    private String key;
                    private String value;

                    public String getKey() {
                        return key;
                    }

                    public void setKey(String key) {
                        this.key = key;
                    }

                    public String getValue() {
                        return value;
                    }

                    public void setValue(String value) {
                        this.value = value;
                    }
                }
            }
        }
    }
}