gpt4 book ai didi

android - 改造 - 预期为 BEGIN_ARRAY 但实际为 BEGIN_OBJECT?

转载 作者:行者123 更新时间:2023-12-05 00:09:18 27 4
gpt4 key购买 nike

我从服务中得到一个 json 结果,如下所示:

{
"result": {
"totalCount": 15,
"resultCount": 2,
"offset": 0,
"limit": 2,
"products": [
{
"id": 10081,
"name": "prod",
"pictureUrl": "url",
"price": 1,
"url": "url",
"briefDescription": "test",
"description": "test",
"pictures": [],
"categoryTitle": "s s",
"categoryId": 53,
"extraInfo": {
"productProperties": [
{
"id": 88,
"value": "6",
"measurementUnit": "s",
"title": "s"
},
{
"id": 89,
"value": "2",
"measurementUnit": "s",
"title": "s s"
},
{
"id": 90,
"value": "2",
"measurementUnit": "s",
"title": "s s s s"
},
{
"id": 91,
"value": "",
"measurementUnit": "",
"title": "s s"
},
{
"id": 92,
"value": "",
"measurementUnit": "",
"title": "s s"
},
{
"id": 93,
"value": "",
"measurementUnit": "",
"title": "s"
},
{
"id": 94,
"value": "",
"measurementUnit": "",
"title": "s"
}
],
"published": false,
"preparationTime": 1,
"keywords": "",
"quantity": 0,
"status": 1
}
},
{
"id": 51,
"name": "nam3",
"pictureUrl": "url",
"price": 495000,
"url": "url",
"briefDescription": "sdsds",
"description": "-",
"pictures": [],
"categoryTitle": "x x x",
"categoryId": 179,
"extraInfo": {
"productProperties": [
{
"id": 67,
"value": "1000",
"measurementUnit": "x",
"title": "x x"
},
{
"id": 68,
"value": "1050",
"measurementUnit": "s",
"title": "x x x"
},
{
"id": 69,
"value": "",
"measurementUnit": "",
"title": "x x"
},
{
"id": 70,
"value": "",
"measurementUnit": "",
"title": "x x"
},
{
"id": 71,
"value": "",
"measurementUnit": "",
"title": "xxxx"
}
],
"published": true,
"preparationTime": 2,
"keywords": "Aswddfe",
"quantity": 93,
"status": 1
}
}
]
}
}

我正在用 retrofit 吼叫:

RetrofitApi.getVendorAdminApi()
.getAdminProductss(userToken, limit, pageNumber, filters)
.enqueue(new Callback<List<ProductsModel>>() {
@Override
public void onResponse(Call<List<ProductsModel>> call, Response<List<ProductsModel>> response) {
if (response.isSuccessful()) {
resultListener.onSuccess(response.body());
} else {
resultListener.onFailure();
}
}

@Override
public void onFailure(Call<List<ProductsModel>> call, Throwable t) {
resultListener.onFailure();
t.printStackTrace();
}
});

但是说我:

Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

下面是我的模型:

public class ProductsModel {

@SerializedName("result")
@Expose
private ResultProducts result;

public ResultProducts getResult() {
return result;
}

public void setResult(ResultProducts result) {
this.result = result;
}

}

最佳答案

你的问题是Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 1 column 2 path $

so change List<ProductsModel> to ProductsModel .

  • 如果 JSONJSONArray , 你可以将它解析为 List (如 List<ProductsModel> )。

  • 如果 JSONJSONObject , 你可以将它解析为 Object (如 ProductsModel )。

改成这个。

@Override
public void onResponse(Call<ProductsModel> call, Response<ProductsModel> response) {
if (response.isSuccessful()) {
resultListener.onSuccess(response.body());
} else {
resultListener.onFailure();
}
}

Call<ProductsModel> getAdminProductss();

关于android - 改造 - 预期为 BEGIN_ARRAY 但实际为 BEGIN_OBJECT?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46754771/

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