gpt4 book ai didi

android - 应为 BEGIN_ARRAY 但在第 1 行第 96 列路径中为 BEGIN_OBJECT

转载 作者:行者123 更新时间:2023-11-30 01:23:15 25 4
gpt4 key购买 nike

这是我的json

{
"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)

最佳答案

你的 json 有错误:

responseB 第一个对象有一个response 对象,第二个对象有response 数组。这是制造问题

{

"success":true,

"error":null,

"responseA":{

"responseB":[
{

"response":{... ***// This is object***
},
"request":"\/observations\/atlanta,ga"
},
{
"response":[ ***// This is Array***
{ ...
}
],
"request":"\/forecasts\/atlanta,ga"
},
... ]

} }

您已经为数组对象创建了相同的结构。希望这有帮助。谢谢

关于android - 应为 BEGIN_ARRAY 但在第 1 行第 96 列路径中为 BEGIN_OBJECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36788277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com