使用 Retrofit 解析 JSON 数组,其中包含对象数组

Parsing JSON array with Array of objects inside with Retrofit

我有来自端点的 json 响应的片段,我需要在其中获取一些消息,但有点返回错误信息或者我做错了:

{
    "data": [
        {
            "alignImages": "left",
            "data": [
                {
                    "content": "Despus de dos aos de la operacin y una intensiva terapia, jvenes que no podan mover sus miembros inferiores y superiores ahora pueden comer, cepi",
                    "id": 179,
                    "title": "Ciruga que reconecta los nervios le devolvi a 13 tetrapljicos la movilidad en",
                    "url_detail": "https://www.elespectador.com/noticias/salud/cirugia-que-reconecta-los-nervios-le-devolvio-13-tetraplejicos-la-movilidad-en-brazos-y-codos-articulo-869",
                    "url_image": "https://storage.googleapis.com/sitidoctor-161813.appspot.com/images/noticia_2.png"
                },
                {
                    ...
                }
            ],
            "imgHeader": "https://storage.googleapis.com/sitidoctor-161813.appspot.com/images/Noticias_Salud.png",
            "titleHeader": "Noticias Salud"
        }
    ],
    "message": "success!",
    "status": 200
}

这是我用来解析改造实例查询响应的模型:

public class NewsResponse {

    @SerializedName("data")
    @Expose
    private List<New> data = null;
    @SerializedName("message")
    @Expose
    private String message;
    @SerializedName("status")
    @Expose
    private Integer status;

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

    public void setData(List<New> data) {
        this.data = data;
    }

    public String getMessage() {
        return message;
    }

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

    public int getStatus() {
        return status;
    }

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

}

我使用这样的改造方式提出请求:

private void handleResponse(NewsResponse newsResponse) {
        Log.e("response", newsResponse.getData().toString());
        if (newsResponse.getData().size() > 0){
            List<New> n = new ArrayList<>();
            for (int i = 0; i < newsResponse.getData().size(); i++){
                New nn = newsResponse.getData().get(i);
                n.add(nn);
            }
            callback.onSuccess(n);
        }
}

但我总是得到一个单一的空值,就像将内部数据数组作为对象返回但无法获取数据,我尝试了一切但一无所获,有什么想法吗?

Reference imagen in debugger

查看您的调试器图像,您的 newsResponse.getData().size() 为 1。列表中唯一的元素的 id、title、content、uridetail 为 null。您正在正确处理响应。您的回复有问题。请检查您是否正确拨打网络电话