如何使用改型获取嵌套的json数组对象?

时间:2018-08-02 09:46:32

标签: android retrofit

如何检索呢? 我尝试为“ sys”创建2个模型类,而另一个为“ sys”的子类创建,但是没有用:

Sys类:

public class Sys {
private ArrayList<SysInfo> sys = new ArrayList<>();

public ArrayList<SysInfo> getSys() {
    return sys;
}

public void setSys(ArrayList<SysInfo> sys) {
    this.sys = sys;
}

SysInfo类

public class SysInfo {
private String country;

public String getCountry() {
    return country;
}

public void setCountry(String country) {
    this.country = country;
}

这是JSON enter image description here

1 个答案:

答案 0 :(得分:1)

获取系统对象用户

import com.google.gson.annotations.SerializedName;

public class SysParent {
    @SerializedName("sys")

    private Sys sysObj;

    public Sys getSysObj() {
        return sysObj;
    }

    public void setSysObj(Sys sysObj) {
        this.sysObj = sysObj;
    }
}

并使用以下类来获取sys中的值。

import com.google.gson.annotations.SerializedName;

public class Sys {

    @SerializedName("country") private String country;

    public String getCountry() {
        return country;
    }

    public void setCountry(String country) {
        this.country = country;
    }
}