[英]Retrofit - JsonSyntaxException when trying to get response.body
所以我試圖從我的服務器獲取response.body,它是GpsCordinates類型的列表。
從服務器我得到這樣的響應:
[
{
"x": 33333,
"y": 333,
"date": 1516532556000
},
{
"x": 3,
"y": 4,
"date": 1516542914000
}
]
請求:
@GET("....")
Call<List<GpsCordinates>> getGPSCordinatesForDay();
我如何得到回應:
Api api = Api.RetrofitInstance.create();
api.getGPSCordinatesForDay().enqueue(new Callback<List<GpsCordinates>>() {
@Override
public void onResponse(Call<List<GpsCordinates>> call, Response<List<GpsCordinates>> response) {
if (response.isSuccessful()) {
List<GpsCordinates> gpsCordinates = response.body();
}
}
@Override
public void onFailure(Call<List<GpsCordinates>> call, Throwable t) {
Log.d("ERROR", t.toString());
}
});
GpsCordinates模型:
@SerializedName("x")
@Expose
private double x;
@SerializedName("y")
@Expose
private double y;
@SerializedName("date")
@Expose
private Date date;
public double getX() {
return x;
}
public void setX(double x) {
this.x = x;
}
public double getY() {
return y;
}
public void setY(double y) {
this.y = y;
}
public Date getDate() {
return date;
}
public void setDate(Date date) {
this.date = date;
}
當我嘗試它時,我得到: D / ERROR:com.google.gson.JsonSyntaxException:1516532556000
使用long代替Date
。 您的服務器發送時間戳(毫秒)。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.