【发布时间】:2018-04-21 08:42:10
【问题描述】:
我有以下 JSON、代码和模型:
这是 JSON 的有线格式
{
"success": "false",
"http": "ok",
"status_code": "200",
"invoice_detail": {
"notifications": [
{
"quantity": "414",
"price": "5412",
"total_price": "15748",
"name": "Axel_Item_5412"
},
{
"quantity": "414",
"price": "5412",
"total_price": "15748",
"name": "Axel_Item_5412"
},
{
"quantity": "414",
"price": "5412",
"total_price": "15748",
"name": "Axel_Item_5412"
},
{
"quantity": "414",
"price": "5412",
"total_price": "15748",
"name": "Axel_Item_5412"
},
{
"quantity": "414",
"price": "5412",
"total_price": "15748",
"name": "Axel_Item_5412"
},
{
"quantity": "414",
"price": "5412",
"total_price": "15748",
"name": "Axel_Item_5412"
},
{
"quantity": "414",
"price": "5412",
"total_price": "15748",
"name": "Axel_Item_5412"
},
{
"quantity": "414",
"price": "5412",
"total_price": "15748",
"name": "Axel_Item_5412"
}
]
},
"sgst": "125478122"
}
这是retrofitCall方法
private void retrofitCall() {
String url= "http://www.amock.io/api/imran.cyber/get-fake";
Call<ListModel> call= apiInterface.getList("", url);
call.enqueue(new Callback<ListModel>() {
@Override
public void onResponse(Call<ListModel> call, Response<ListModel> response) {
if (response.isSuccessful()){
String s= response.body().getInvoice_detail();
Log.e(TAG, "onResponse: "+s);
}
}
@Override
public void onFailure(Call<ListModel> call, Throwable t) {
Log.e(TAG, "onFailure: "+t.getMessage());
}
});
}
这是模型类
public class ListModel {
@SerializedName("invoice_detail")
public String invoice_detail;
public ListModel(String invoice_detail) {
this.invoice_detail = invoice_detail;
}
public String getInvoice_detail() {
return invoice_detail;
}
public void setInvoice_detail(String invoice_detail) {
this.invoice_detail = invoice_detail;
}
我得到这个错误:
11-08 10:09:18.489 3578-3578/? E/MainActivity::onFailure: java.lang.IllegalStateException: 预期为字符串,但在第 5 行第 22 列路径 $.invoice_detail 处为 BEGIN_OBJECT
我不确定出了什么问题:我的 JSON、我的代码还是我的模型?
【问题讨论】:
-
你为什么不试试?
-
你可以自己查:json.org
-
但无法获取 **invoice_detail **