[英]Retrofit - JsonSyntaxException when trying to get response.body
So I am trying to get response.body from my server, which is list of type GpsCordinates. 所以我试图从我的服务器获取response.body,它是GpsCordinates类型的列表。
From server I get response like this: 从服务器我得到这样的响应:
[
{
"x": 33333,
"y": 333,
"date": 1516532556000
},
{
"x": 3,
"y": 4,
"date": 1516542914000
}
]
Request: 请求:
@GET("....")
Call<List<GpsCordinates>> getGPSCordinatesForDay();
how I get the response: 我如何得到回应:
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 model: 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;
}
And when I try it I get: D/ERROR: com.google.gson.JsonSyntaxException: 1516532556000 当我尝试它时,我得到: D / ERROR:com.google.gson.JsonSyntaxException:1516532556000
Use long instead of Date
. 使用long代替
Date
。 Your server sends timestamp (millis). 您的服务器发送时间戳(毫秒)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.