创建POJO以进行改造

时间:2015-10-11 18:33:16

标签: android gson retrofit

我的json回复是

[
  {
    "responseValue":"error"
  },
  {
    "responseData":
    {
      "erroCode":"1",
      "errorDesc":"Invalid Client Key"
    }
  }
]

POJO类的结构是什么? 我正在使用Retrofit 1.9.0。 我正在使用gson转换器。 我应该如何在适配器接口中声明该函数以及如何调用?

提前致谢

2 个答案:

答案 0 :(得分:1)

查看以下链接,它有各种各样的json to pojo选项。

http://www.jsonschema2pojo.org/

答案 1 :(得分:0)

http://pojo.sodhanalibrary.com/

    {
        "status": "success",
        "message": "Records found.",
        "data": {
            "verify_details": [
                {
                    "key": "Hologram No",
                    "value": "J10001"
                },
                {
                    "key": "Retailer",
                    "value": null
                }
            ]
        }
    }


package com.holostik.esecure.pojo;

import com.google.gson.annotations.SerializedName;

import java.util.ArrayList;
import java.util.List;

public class NumbersOfScanPojo {

    @SerializedName("status")
    public String status;

    @SerializedName("message")
    public String message;

    private Data data;

    public Data getData() {
        return data;
    }

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

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public class Data {
        public List<NumbersOfScanPojo.Verify_details> verify_details = new ArrayList<>();

        public List<Verify_details> getVerify_details() {
            return verify_details;
        }

        public void setVerify_details(List<Verify_details> verify_details) {
            this.verify_details = verify_details;
        }

        @Override
        public String toString() {
            return "ClassPojo [verify_details = " + verify_details + "]";
        }
    }


    public class Verify_details {
        @SerializedName("key")
        private String key;

        @SerializedName("value")
        private String value;

        public String getValue() {
            return value;
        }

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

        public String getKey() {
            return key;
        }

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

        @Override
        public String toString() {
            return "ClassPojo [value = " + value + ", key = " + key + "]";
        }
    }

}