Java 改型-JsonSyntaxException尝试获取response.body时
所以我试图从我的服务器获取response.body,这是GpsCordinates类型的列表 从服务器上我得到如下响应:Java 改型-JsonSyntaxException尝试获取response.body时,java,android,android-studio,retrofit,retrofit2,Java,Android,Android Studio,Retrofit,Retrofit2,所以我试图从我的服务器获取response.body,这是GpsCordinates类型的列表 从服务器上我得到如下响应: [ { "x": 33333, "y": 333, "date": 1516532556000 }, { "x": 3, "y": 4, "date": 1516542914000 } ] 请求: @GET("....") Call<List<GpsCordinates>> getGPSCordinatesForDay(); 当我尝试时
[
{
"x": 33333,
"y": 333,
"date": 1516532556000
},
{
"x": 3,
"y": 4,
"date": 1516542914000
}
]
请求:
@GET("....")
Call<List<GpsCordinates>> getGPSCordinatesForDay();
当我尝试时,我得到:
D/ERROR:com.google.gson.JsonSyntaxException:1516532556000使用long而不是
日期
。您的服务器发送时间戳(毫秒)。在我的服务器中,日期也是java.util.date类型
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());
}
});
@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;
}