1. 程式人生 > >Gson解析json時出現Expected a string but was BEGIN_ARRAY異常,由此發現Gson和FastJson區別

Gson解析json時出現Expected a string but was BEGIN_ARRAY異常,由此發現Gson和FastJson區別

結果:
[{"catalog":"環境搭建","article":[{"read":1,"column":9,"id":2,"title":"IntelliJIDEA環境搭建","slug":"static/kotlin_article/0_1.html"},{"read":1,"column":9,"id":3,"title":"Eclipse環境搭建","slug":"static/kotlin_article/0_2.html"},{"read":1,"column":9,"id":4,"title":"使用命令列編譯","slug":"static/kotlin_article/0_3.html"},{"read":1,"column":9,"id":5,"title":"Android環境搭建","slug":"static/kotlin_article/0_4.html"}]}]
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 2 column 16 path $.detailcom.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected a string but was BEGIN_ARRAY at line 2 column 16 path $.detailat com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:224)at com.google.gson.Gson.fromJson(Gson.java:888)at com.google.gson.Gson.fromJson(Gson.java:853)at com.google.gson.Gson.fromJson(Gson.java:802)at com.google.gson.Gson.fromJson(Gson.java:774)at per.wsj.myapplication.ExampleUnitTest.useGson(ExampleUnitTest.java:60)at per.wsj.myapplication.ExampleUnitTest.jsonTest(ExampleUnitTest.java:43)at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)at java.lang.reflect.Method.invoke(Method.java:498)
果然Fastjson是可以的,好坑啊