這是我的JSON預計BEGIN_ARRAY但BEGIN_OBJECT在行1列96路
{
"success": true,
"error": null,
"responseA": {
"responseB": [{
"response": {...},
"request": "\/observations\/atlanta,ga"
}, {
"response": [{...}],
"request": "\/forecasts\/atlanta,ga"
},
...
]
}
}
我創造我的課從這裏JSON: http://www.jsonschema2pojo.org/
,我覺得標題的誤差從數組和對象的兩個「響應」。
正如我所說的通過Retrofit來分析,我如何用Retrofit2.0分析兩種類型(數組和對象)的「repsonse」這樣的json?謝謝〜*
Retrofit retrofit = new Retrofit.Builder()
.baseUrl(BASE_URL)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJavaCallAdapterFactory.create())
.build();`
這是日誌:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 96 path $.response.responses[0].response
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:200)
at com.google.gson.internal.bind.TypeAdapterRuntimeTypeWrapper.read(TypeAdapterRuntimeTypeWrapper.java:40)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:81)
at com.google.gson.internal.bind.CollectionTypeAdapterFactory$Adapter.read(CollectionTypeAdapterFactory.java:60)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$1.read(ReflectiveTypeAdapterFactory.java:103)
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:196)
at com.google.gson.Gson.fromJson(Gson.java:810)
at com.google.gson.Gson.fromJson(Gson.java:775)
at retrofit.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:36)
at retrofit.GsonResponseBodyConverter.convert(GsonResponseBodyConverter.java:24)
at retrofit.OkHttpCall.parseResponse(OkHttpCall.java:148)
at retrofit.OkHttpCall.execute(OkHttpCall.java:116)
at retrofit.ExecutorCallAdapterFactory$ExecutorCallbackCall.execute(ExecutorCallAdapterFactory.java:61)
請張貼錯誤的logcat .... – sushildlh
好像我改變從對象數組我的反應,它會說需要一個ARRY卻得到了一個對象.... – JoeKevin
您的JSON開始與arrya – sushildlh