我尝试通过Retrofit 2从服务器获取JSON,但是我收到了这个错误:
com.google.gson.JsonSyntaxException:Mon Feb 29 08:12:40 GMT + 00:00 2016
这是我启动Gson和Retrofit的一些代码:
Gson gson = new GsonBuilder()
.setDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
.create();
Retrofit client = new Retrofit.Builder()
.baseUrl(AppConfig.BASE_URL)
.addConverterFactory(GsonConverterFactory.create(gson))
.build();
RESTDatabaseDAO service = client.create(RESTDatabaseDAO.class);
Call<Message> call = service.getLastMessage(objectItem.getUserId(), AppConfig.USER_ID);
call.enqueue(new Callback<Message>() {
@Override
public void onResponse(Call<Message> call, Response<Message> response) {
if (response.isSuccess()) {
Message message = response.body();
Log.i("In retrofit method success message", response.body() + "");
viewHolder.tv_lastMessage.setText(message.getMessage());
} else {
Log.i("In retrofit method failure", response.body() + "");
}
}
@Override
public void onFailure(Call<Message> call, Throwable t) {
Log.i("In retrofit method failure message", t.toString());
}
});
这是我在数据库中的数据:
Mon Feb 29 08:12:40 GMT + 00:00 2016
更新 这是我的JSON字符串:
{&#34; messageId&#34;:1,&#34; message&#34;:&#34; new&#34;,&#34; expiresTime&#34;:&#34; Fri Mar 04 02 :12:39 GMT + 00:00 2016&#34;,&#34; senderId&#34;:2,&#34; userId&#34;:1}