关于Gson解析时间时的问题
com.google.gson.JsonSyntaxException: 1461689198000 04-27 00:46:51.159 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:74) 04-27 00:46:51.159 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:59) 04-27 00:46:51.159 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.DateTypeAdapter.read(DateTypeAdapter.java:41) 04-27 00:46:51.159 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:116) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:216) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:116) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:216) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.Gson.fromJson(Gson.java:879) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.Gson.fromJson(Gson.java:844) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.Gson.fromJson(Gson.java:793) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.yurikami.lib.net.parser.impl.ModelParser.parse(ModelParser.java:48) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.yurikami.lib.net.UICallBack.onResponse(UICallBack.java:54) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at okhttp3.RealCall$AsyncCall.execute(RealCall.java:133) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at okhttp3.internal.NamedRunnable.run(NamedRunnable.java:32) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at java.lang.Thread.run(Thread.java:818) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: Caused by: java.text.ParseException: Failed to parse date ["1461689198000']: Invalid time zone indicator '9' (at offset 0) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:274) 04-27 00:46:51.160 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.DateTypeAdapter.deserializeToDate(DateTypeAdapter.java:72) 04-27 00:46:51.166 17190-20868/link.ebbinghaus.planning W/System.err: ... 16 more 04-27 00:46:51.166 17190-20868/link.ebbinghaus.planning W/System.err: Caused by: java.lang.IndexOutOfBoundsException: Invalid time zone indicator '9' 04-27 00:46:51.166 17190-20868/link.ebbinghaus.planning W/System.err: at com.google.gson.internal.bind.util.ISO8601Utils.parse(ISO8601Utils.java:245) 04-27 00:46:51.166 17190-20868/link.ebbinghaus.planning W/System.err: ... 17 more
gson默认可能无法识别这种格式,可能需要你写个转换适配器才行
很好的解决了我的问题,一开始以为是 gson.setDateFormat(DateFormat.LONG) .