【发布时间】:2018-01-27 01:33:23
【问题描述】:
如果我尝试从我的 Retrofit 调用中获取数据,它是空的。可能是因为我使用了错误的数据类型。不确定它是 Array 还是 ArrayList 也许有人可以帮助我。
API:https://chasing-coins.com/api/v1/top-coins/100
界面:
@GET("api/v1/top-coins/{top}")
Call<JSONArray> getStats(@Path("top")String top);
类:
public class Coinstats {
@SerializedName("symbol")
@Expose
private String symbol;
@SerializedName("cap")
@Expose
private String cap;
@SerializedName("change")
@Expose
private Change change;
@SerializedName("price")
@Expose
private String price;
@SerializedName("coinheat")
@Expose
private Integer coinheat;
@SerializedName("url")
@Expose
private String url;
public String getSymbol() {
return symbol;
}
public void setSymbol(String symbol) {
this.symbol = symbol;
}
public String getCap() {
return cap;
}
public void setCap(String cap) {
this.cap = cap;
}
public Change getChange() {
return change;
}
public void setChange(Change change) {
this.change = change;
}
public String getPrice() {
return price;
}
public void setPrice(String price) {
this.price = price;
}
public Integer getCoinheat() {
return coinheat;
}
public void setCoinheat(Integer coinheat) {
this.coinheat = coinheat;
}
public String getUrl() {
return url;
}
public void setUrl(String url) {
this.url = url;
}
}
呼叫:
call2.enqueue(new Callback<JSONArray>() {
@Override
public void onResponse(Call<JSONArray> call, Response<JSONArray> response) {
Log.w("Stats", response.message());
}
@Override
public void onFailure(Call<JSONArray> call, Throwable t) {
Log.w("no Stats", t.toString());
}
});
Respones Message 给了我一个很好的 200 但 response.body 是空的。 谢谢!
【问题讨论】:
-
结果不是数组。它是一个对象。
标签: android json retrofit retrofit2