我是新的改造。下面是我的代碼來獲得供應商名單
樣品JSON響應是JSON數組&不是JSON對象
[
{
"Key" : "1",
"Value" : "xyz"
},
{
"Key" : "2",
"Value" : "abc"
}
]
下面是我的代碼
private void callToRetrofit() {
ApiInterface apiInterface = ApiClient.getApiClient()
.create(ApiInterface.class);
Call<List<SD_Checklist_Supplier_Model>> call = apiInterface.getVendors();
call.enqueue(new Callback<List<SD_Checklist_Supplier_Model>>() {
@Override
public void onResponse(Call<List<SD_Checklist_Supplier_Model>> call, Response<List<SD_Checklist_Supplier_Model>> response) {
Log.v("onResponse", " : ok" + response == null ? " null" : "okkkk" + response.toString());
}
@Override
public void onFailure(Call<List<SD_Checklist_Supplier_Model>> call, Throwable t) {
Log.v("onFailure", " : " + t.toString());
}
});
}
Model類
public class SD_Checklist_Supplier_Model {
@SerializedName("Key")
private String supplierID;
@SerializedName("Value")
private String supplierName;
private boolean isSupplierSelected;
public String getSupplierID() {
return supplierID;
}
public void setSupplierID(String supplierID) {
this.supplierID = supplierID;
}
public String getSupplierName() {
return supplierName;
}
public void setSupplierName(String supplierName) {
this.supplierName = supplierName;
}
public boolean isSupplierSelected() {
return isSupplierSelected;
}
public void setSupplierSelected(boolean supplierSelected) {
isSupplierSelected = supplierSelected;
}
}
目前,我得到
com.google.gson.JsonSyntaxException:java.lang.IllegalStateException: 預計BEGIN_OBJECT但BEGIN_ARRAY位於第1行第2列路徑$
請幫助我。
檢查您的API中郵差。它必須進入一個不在數組中的對象。如錯誤提及。 – sushildlh
正如我已經提到的。它是json數組,不是標準的json對象,它內部 – VVB
你會分享API的網址嗎? – sushildlh