ホームページ  >  に質問  >  本文

java - 关于Gson解析时间时的问题

用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
迷茫迷茫2764日前785

全員に返信(3)返信します

  • PHP中文网

    PHP中文网2017-04-17 17:48:50

    リーリー

    ここから来てください~
    http://stackoverflow.com/questions/5671373/unparseable-date-1302828677828-trying-to-deserialize-with-gson-a-millisecond

    Gson の Date.class への逆シリアル化の操作

    返事
    0
  • PHP中文网

    PHP中文网2017-04-17 17:48:50

    gson はデフォルトではこの形式を認識しない可能性があるため、変換アダプターを作成する必要がある場合があります

    返事
    0
  • PHP中文网

    PHP中文网2017-04-17 17:48:50

    最初は gson.setDateFormat(DateFormat.LONG) だと思いました。

    返事
    0
  • キャンセル返事