私は以下の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 $
したがって、に変更
List<ProductsModel>
しProductsModel
ます。
場合JSON
でJSONArray
、あなたはそれを解析することができますList
(のようにList<ProductsModel>
)。
場合JSON
でJSONObject
、あなたはそれを解析することができます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();
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加