简体   繁体   English

如何从 django rest api 获得结果?

[英]how get results from django rest api?

how get results from django rest api?如何从 django rest api 获得结果?

https://pastebin.com/nsA3xRtr

https://pastebin.com/QWTGaYAF

https://pastebin.com/hDwCBPd7

It's work if I disabled Pagination如果我禁用分页,它的工作

this api这 api

https://igbaria.pythonanywhere.com/api/test/city/

you should create a class as below to pars this JSON您应该如下创建一个 class 来解析这个 JSON

public class Response{


    @SerializedName("next")
    String next;
    @SerializedName("previous")
    String previous;
    @SerializedName("count")
    int count;
    @SerializedName("count")
    int count;

    @SerializedName("results")
    ArrayList<City> results;
}

Error occurs because you map json to java class incorrectly.发生错误是因为您的 map json 到 java class 不正确。 Use this ones:使用这个:

import java.util.List;
import com.google.gson.annotations.SerializedName;

public class CityListItemResponse {

    @SerializedName("count")
    public Integer count;
    @SerializedName("next")
    public String next;
    @SerializedName("previous")
    public Object previous;
    @SerializedName("results")
    public List<City> results = null;
}


import com.google.gson.annotations.SerializedName;

public class City {

    @SerializedName("id")
    public Integer id;
    @SerializedName("title")
    public String title;
}

For creating data classes correctly I advise U to use this instrument link为了正确创建数据类,我建议你使用这个仪器链接

Just select your options paste JSON and look at preview只需 select 您的选项粘贴 JSON 并查看预览

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM