Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 492
今天遇上了Gson解析的BUG,卡了几个小时,急疯了最后找到原因了,最后发现下面两个json 的schedule字段一个是[] 一个是{}
保错
Exception in thread "main" com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 492
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:176)at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:93)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:172)
at com.google.gson.Gson.fromJson(Gson.java:795)
at com.google.gson.Gson.fromJson(Gson.java:761)
at com.google.gson.Gson.fromJson(Gson.java:710)
at com.google.gson.Gson.fromJson(Gson.java:682)
at test.AATT.main(AATT.java:24)
Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 492
at com.google.gson.stream.JsonReader.expect(JsonReader.java:339)
at com.google.gson.stream.JsonReader.beginObject(JsonReader.java:322)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:165)
... 9 more
解析的字符串
{
-
status: "success", result: { id: 141, car_wash_id: 141, status: 1, license_plate_number: "TYYUuui", user_id: 38, paid_client: 0, paid_server: 0, cancel_reason: "", score: 0, price: 20, comment: "", updated_at: "2014-12-26 16:50:15", icon_link: " ", car_location: { car_location: { car_location_id: 7, location_name: "1号楼旁边" } }, schedule: { schedule_id: 13, reservation_start: "2014-12-26 08:00:00", reservation_end: "2014-12-27 04:00:00", work_start: "2014-12-27 06:30:00", work_end: "2014-12-27 07:30:00", status: 1 }, source_front: [ ], source_back: [ ], source_comment: [ ] }
{
-
status: "success", result: { id: 5, car_wash_id: 5, status: 5, license_plate_number: "沪222222", user_id: 3, paid_client: 0, paid_server: 0, cancel_reason: "", score: 4, price: 20, comment: " uuii", updated_at: "2014-12-26 16:08:42", icon_link: " ", car_location: { car_location: { car_location_id: 11, location_name: "5号楼旁边" } }, schedule: [ ], source_front: [ { source_id: 7, source_url: " ", source_big_url: " " }, { source_id: 8, source_url: " ", source_big_url: " " } ], source_back: [ { source_id: 9, source_url: " ", source_big_url: " " }, { source_id: 10, source_url: " ", source_big_url: " " } ], source_comment: [ { source_id: 55, source_url: " ", source_big_url: " " } ] }