简体   繁体   中英

how get results from django rest api?

how get results from django rest api?

https://pastebin.com/nsA3xRtr

https://pastebin.com/QWTGaYAF

https://pastebin.com/hDwCBPd7

It's work if I disabled Pagination

this api

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

you should create a class as below to pars this 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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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