Gson如何将Json置于具有随机属性的Pojo中

时间:2018-07-26 09:26:18

标签: android gson

请帮助我为此json对象创建一个Java PojoClass。 我使用Android SDK + Gson。 主要问题是在Pojo类Jsons中如何精确存储"11374675":之类的随机属性名称? 帮帮我,请把它证明给Pojo。

[{
    "id": 1298850,
    "desc": "",
    "department": "",
    "email": "",
    "use_status": 0,
    "use_cc_numbers": 0,
    "password": null,
    "default_number_id": 1298855,
    "abonent_id": 300850088,
    "call_center": 0,
    "name": "10 \u0441\u0442\u0435\u043d\u0434 linksys SPA3102",
    "abonent_role": 30964,
    "abonent_parent_role": 0,
    "dial_alg": 1,
    "is_system": 0,
    "transfer_number": "6704",
    "pin_specified": null,
    "login": null,
    "operator_groups": {
        "11374675": {
            "order": "0",
            "priority": "1"
        },
        "832251": {
            "order": "1",
            "priority": "1"
        }
    }
}]

1 个答案:

答案 0 :(得分:0)

Response.java

package com.bravo.app.JsonPojo;


import com.google.gson.annotations.SerializedName;

public class Response{

    @SerializedName("is_system")
    private int isSystem;

    @SerializedName("dial_alg")
    private int dialAlg;

    @SerializedName("transfer_number")
    private String transferNumber;

    @SerializedName("abonent_role")
    private int abonentRole;

    @SerializedName("operator_groups")
    private OperatorGroups operatorGroups;

    @SerializedName("use_status")
    private int useStatus;

    @SerializedName("login")
    private Object login;

    @SerializedName("abonent_parent_role")
    private int abonentParentRole;

    @SerializedName("password")
    private Object password;

    @SerializedName("call_center")
    private int callCenter;

    @SerializedName("pin_specified")
    private Object pinSpecified;

    @SerializedName("name")
    private String name;

    @SerializedName("default_number_id")
    private int defaultNumberId;

    @SerializedName("id")
    private int id;

    @SerializedName("abonent_id")
    private int abonentId;

    @SerializedName("department")
    private String department;

    @SerializedName("email")
    private String email;

    @SerializedName("use_cc_numbers")
    private int useCcNumbers;

    @SerializedName("desc")
    private String desc;

    public void setIsSystem(int isSystem){
        this.isSystem = isSystem;
    }

    public int getIsSystem(){
        return isSystem;
    }

    public void setDialAlg(int dialAlg){
        this.dialAlg = dialAlg;
    }

    public int getDialAlg(){
        return dialAlg;
    }

    public void setTransferNumber(String transferNumber){
        this.transferNumber = transferNumber;
    }

    public String getTransferNumber(){
        return transferNumber;
    }

    public void setAbonentRole(int abonentRole){
        this.abonentRole = abonentRole;
    }

    public int getAbonentRole(){
        return abonentRole;
    }

    public void setOperatorGroups(OperatorGroups operatorGroups){
        this.operatorGroups = operatorGroups;
    }

    public OperatorGroups getOperatorGroups(){
        return operatorGroups;
    }

    public void setUseStatus(int useStatus){
        this.useStatus = useStatus;
    }

    public int getUseStatus(){
        return useStatus;
    }

    public void setLogin(Object login){
        this.login = login;
    }

    public Object getLogin(){
        return login;
    }

    public void setAbonentParentRole(int abonentParentRole){
        this.abonentParentRole = abonentParentRole;
    }

    public int getAbonentParentRole(){
        return abonentParentRole;
    }

    public void setPassword(Object password){
        this.password = password;
    }

    public Object getPassword(){
        return password;
    }

    public void setCallCenter(int callCenter){
        this.callCenter = callCenter;
    }

    public int getCallCenter(){
        return callCenter;
    }

    public void setPinSpecified(Object pinSpecified){
        this.pinSpecified = pinSpecified;
    }

    public Object getPinSpecified(){
        return pinSpecified;
    }

    public void setName(String name){
        this.name = name;
    }

    public String getName(){
        return name;
    }

    public void setDefaultNumberId(int defaultNumberId){
        this.defaultNumberId = defaultNumberId;
    }

    public int getDefaultNumberId(){
        return defaultNumberId;
    }

    public void setId(int id){
        this.id = id;
    }

    public int getId(){
        return id;
    }

    public void setAbonentId(int abonentId){
        this.abonentId = abonentId;
    }

    public int getAbonentId(){
        return abonentId;
    }

    public void setDepartment(String department){
        this.department = department;
    }

    public String getDepartment(){
        return department;
    }

    public void setEmail(String email){
        this.email = email;
    }

    public String getEmail(){
        return email;
    }

    public void setUseCcNumbers(int useCcNumbers){
        this.useCcNumbers = useCcNumbers;
    }

    public int getUseCcNumbers(){
        return useCcNumbers;
    }

    public void setDesc(String desc){
        this.desc = desc;
    }

    public String getDesc(){
        return desc;
    }

    @Override
    public String toString(){
        return 
            "Response{" + 
            "is_system = '" + isSystem + '\'' + 
            ",dial_alg = '" + dialAlg + '\'' + 
            ",transfer_number = '" + transferNumber + '\'' + 
            ",abonent_role = '" + abonentRole + '\'' + 
            ",operator_groups = '" + operatorGroups + '\'' + 
            ",use_status = '" + useStatus + '\'' + 
            ",login = '" + login + '\'' + 
            ",abonent_parent_role = '" + abonentParentRole + '\'' + 
            ",password = '" + password + '\'' + 
            ",call_center = '" + callCenter + '\'' + 
            ",pin_specified = '" + pinSpecified + '\'' + 
            ",name = '" + name + '\'' + 
            ",default_number_id = '" + defaultNumberId + '\'' + 
            ",id = '" + id + '\'' + 
            ",abonent_id = '" + abonentId + '\'' + 
            ",department = '" + department + '\'' + 
            ",email = '" + email + '\'' + 
            ",use_cc_numbers = '" + useCcNumbers + '\'' + 
            ",desc = '" + desc + '\'' + 
            "}";
        }
}

JsonMember832251.java

package com.bravo.app.JsonPojo;

import com.google.gson.annotations.SerializedName;

public class JsonMember832251{

    @SerializedName("priority")
    private String priority;

    @SerializedName("order")
    private String order;

    public void setPriority(String priority){
        this.priority = priority;
    }

    public String getPriority(){
        return priority;
    }

    public void setOrder(String order){
        this.order = order;
    }

    public String getOrder(){
        return order;
    }

    @Override
    public String toString(){
        return 
            "JsonMember832251{" + 
            "priority = '" + priority + '\'' + 
            ",order = '" + order + '\'' + 
            "}";
        }
}

JsonMember11374675.java

package com.bravo.app.JsonPojo;

import com.google.gson.annotations.SerializedName;

public class JsonMember11374675{

    @SerializedName("priority")
    private String priority;

    @SerializedName("order")
    private String order;

    public void setPriority(String priority){
        this.priority = priority;
    }

    public String getPriority(){
        return priority;
    }

    public void setOrder(String order){
        this.order = order;
    }

    public String getOrder(){
        return order;
    }

    @Override
    public String toString(){
        return 
            "JsonMember11374675{" + 
            "priority = '" + priority + '\'' + 
            ",order = '" + order + '\'' + 
            "}";
        }
}

OperatorGroups.java

package com.bravo.app.JsonPojo;

import com.google.gson.annotations.SerializedName;

public class OperatorGroups{

    @SerializedName("832251")
    private JsonMember832251 jsonMember832251;

    @SerializedName("11374675")
    private JsonMember11374675 jsonMember11374675;

    public void setJsonMember832251(JsonMember832251 jsonMember832251){
        this.jsonMember832251 = jsonMember832251;
    }

    public JsonMember832251 getJsonMember832251(){
        return jsonMember832251;
    }

    public void setJsonMember11374675(JsonMember11374675 jsonMember11374675){
        this.jsonMember11374675 = jsonMember11374675;
    }

    public JsonMember11374675 getJsonMember11374675(){
        return jsonMember11374675;
    }

    @Override
    public String toString(){
        return 
            "OperatorGroups{" + 
            "832251 = '" + jsonMember832251 + '\'' + 
            ",11374675 = '" + jsonMember11374675 + '\'' + 
            "}";
        }
}