如何从django rest api获取结果?
https://pastebin.com/nsA3xRtr
https://pastebin.com/QWTGaYAF
https://pastebin.com/hDwCBPd7如果我禁用了分页,这就是工作
本接口
https://igbaria.pythonanywhere.com/api/test/city/发布于 2021-03-24 17:25:11
您应该创建一个类来解析这个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;
}发布于 2021-03-24 17:41:51
错误是因为您错误地将json映射到java类。使用以下命令:
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;
}为了正确创建数据类,我建议您使用此仪器link
只需选择选项,粘贴JSON并查看预览
https://stackoverflow.com/questions/66773532
复制相似问题