无法从嵌套的JSON改造Android Studio获取价值

我想从嵌套的json中获取值并使用改造。 LicenseCDL和LicenseVDL类的值均为null。如何从两个数组中获取数据?我在哪里缺少Java类?

这就是Json的样子。

{
    "data": {
        "LicenseCDL": [
            {
                "class_code": "B2",
                "invoice_num": "W1007INV20051",
                "total": "1484.00",
                "created_at": "2020-05-18 08:56:13"
            }
        ],
        "LicenseVDL": [
            {
                "class_code": "PSV VAN",
                "invoice_num": "W1007INV20052",
                "total": "583.00",
                "created_at": "2020-05-18 10:12:13"
            }
        ]
    },
    "status": "1",
    "message": "record found."
}

这是LicenseClassModel

public class LicenseClassModel {

@SerializedName("LicenseCDL")
private List<LicenseCDL> LicenseCDL;
@SerializedName("LicenseVDL")
private List<LicenseVDL> LicenseVDL;

@SerializedName("message")
private String message;
@SerializedName("status")
private String status;

public List<LicenseClassModel.LicenseCDL> getLicenseCDL() {
    return LicenseCDL;
}

public List<LicenseClassModel.LicenseVDL> getLicenseVDL() {
    return LicenseVDL;
}

public String getMessage() {
    return message;
}

public String getStatus() {
    return status;
}

public static class LicenseCDL {

    @SerializedName("class_code")
    private String classCode;
    @SerializedName("data")
    private List<LicenseDataItem> data;

    public String getClassCode() {
        return classCode;
    }

    public List<LicenseDataItem> getData() {
        return data;
    }
}

public static class LicenseVDL {

    @SerializedName("class_code")
    private String classCode;
    @SerializedName("data")
    private List<LicenseDataItem> data;

    public String getClassCode() {
        return classCode;
    }

    public List<LicenseDataItem> getData() {
        return data;
    }
}

这是我想要获得价值的方法

 private void callLicenseApi() {
        Call<LicenseClassModel> CheckCall = apiInterface.LICENSE_CLASS_LIST_CALL(String.valueOf(UserData.getId()));
        CheckCall.enqueue(new Callback<LicenseClassModel>() {
            @Override
            public void onResponse(@NonNull Call<LicenseClassModel> call, @NonNull Response<LicenseClassModel> response) {
                Log.i("???","value cdl: "  + response.body().getLicenseCDL()); //output: value cdl: null 
                Log.i("???","value vdl: "  + response.body().getLicenseVDL()); //output: value cdl: null 
            }

        @Override
        public void onFailure(Call<LicenseClassModel> call, Throwable t) {
            Log.i("???","Erorr : "  + t.getMessage());
        }
    });
}
评论
菊花怒放
菊花怒放

LicenseCDL和LicenseVDL在“数据”密钥中,因此您需要更新类

public class LicenseClassModel {

@SerializedName("data")
@Expose
private Data data;
@SerializedName("status")
@Expose
private String status;
@SerializedName("message")
@Expose
private String message;

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 {

@SerializedName("LicenseCDL")
@Expose
private List<LicenseCDL> licenseCDL = null;
@SerializedName("LicenseVDL")
@Expose
private List<LicenseVDL> licenseVDL = null;

public List<LicenseCDL> getLicenseCDL() {
return licenseCDL;
}

public void setLicenseCDL(List<LicenseCDL> licenseCDL) {
this.licenseCDL = licenseCDL;
}

public List<LicenseVDL> getLicenseVDL() {
return licenseVDL;
}

public void setLicenseVDL(List<LicenseVDL> licenseVDL) {
this.licenseVDL = licenseVDL;
}

}
点赞
评论