如何使用改造解析 json 数组?

How to parse json array using retrofit?

我的回复是这样的..

{
    "IsSuccess": true,
    "ResponseObject": ["one", "two", "three", "four", "five"]
}}

我试图通过创建 POJO 来做到这一点。请帮助我解决问题。

你的POJOclass应该是这样的

public class TempParams {
    /**
     * IsSuccess : true
     * ResponseObject : ["one","two","three","four","five"]
     */

    private boolean IsSuccess;
    private List<String> ResponseObject;

    public boolean isIsSuccess() {
        return IsSuccess;
    }

    public void setIsSuccess(boolean IsSuccess) {
        this.IsSuccess = IsSuccess;
    }

    public List<String> getResponseObject() {
        return ResponseObject;
    }

    public void setResponseObject(List<String> ResponseObject) {
        this.ResponseObject = ResponseObject;
    }

}

成功获取响应对象后,你必须像这样转换它。

Gson gson = new Gson();
TempParams model = gson.fromJson(mObject.toString(), TempParams.class);

现在您可以从 POJO 中获取价值 class。