我得到一個json
結果從服務與改造像波紋管:改裝 - 預計BEGIN_ARRAY,但是BEGIN_OBJECT?
{
"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;
}
}
您還可以添加您的ResultProducts模型類 –
在此URL(http://www.jsonschema2pojo.org/)中複製上述模型並查看模型。 –