gpt4 book ai didi

java - 应为 BEGIN_ARRAY,但在第 1 行第 53 列路径 $.data 处为 BEGIN_OBJECT

转载 作者:行者123 更新时间:2023-12-02 10:31:48 26 4
gpt4 key购买 nike

我正在尝试使用改造来显示从 JSON 到 RecyclerView 的数据,但我总是收到此错误,而且我不知道我做错了什么。

错误日志

E/response-failure-coy:retrofit2.ExecutorCallAdapterFactory$ExecutorCallbackCall@d07e1a7
2018-12-02 20:06:05.182 19205-19205/com.qiscus.qismo.chat

E/Error Kims:java.lang.IllegalStateException:预期为 BEGIN_ARRAY,但在第 1 行第 53 列路径 $.data 处为 BEGIN_OBJECT

ApiInterface.java

@FormUrlEncoded
@POST("order-management-data-by-salesperson")
Call<OrderListModel> getOrderList(@Field("sales_people_id") String salesPeopleId);

JSON 响应

{
"code": 100,
"status": "Showing Data Success",
"data": {
"current_page": 1,
"data": [
{
"mokita_transact_id": 2,
"diab_transact_id": "2",
"order_status": "cancel",
"leasing_status": "approved",
"id_card_num": "1",
"hot_leads_id": 2,
"qty": 1,
"retail_dealer_id": 1,
"rd_code": "1",
"customer_name": "arya jelek",
"birthdate": "2018-11-27",
"gender": 1,
"address": "Jalan",
"kelurahan_id": 1,
"kelurahan": "1",
"kecamatan_id": 1,
"kecamatan": "1",
"customer_number": "082283494984",
"kota_id": 1,
"kota": 1,
"postal_code": 1,
"payment_option_id": 1,
"payment_type": "1",
"datetime": "123",
"product_variant_id": 9,
"model_code": "2",
"color_code": "1",
"credit_provider_id": 1,
"dp": 11000,
"credit_term_id": 1,
"credit_term": 123,
"monthly_installment": 12,
"sales_people_id": "14",
"spk_number": 1,
"is_indent": 1,
"hot_leads": {
"id": 2,
"sales_person_id": 14,
"sales_person": {
"id": 14,
"id_source_MD": 1,
"id_source_RD": 1,
"role": "SP",
"username": "ABE.SP",
"email": "abe-sp@bcg.com",
"sdk_email": "9rjYA_abe-sp@bcg.com",
"phone_number": "081288800908",
"role_app": "SP"
}
},
"payment_detail": {
"id": 1,
"name": "Cash",
"description": "Cash"
},
"product_variant_motor": {
"id": 9,
"ahm_sku_id": 9,
"ahm_sku": "Y1G02N02S1 A/T",
"type": "Beat Pop ESP CW",
"bypass_color": 0,
"product_category_id": 1,
"product_category": "MATIC",
"product_unit_id": 3,
"product_unit": "Beat",
"md_sku_id": "H9",
"main_dealer_type": "Beat Pop ESP CW",
"otr_price": 5000009,
"city_id": 2,
"main_dealer_id": 1,
"lowest_dp_amount": 6000000,
"lowest_monthly_installment": 1000000
}
}
],
"first_page_url": "http://23.101.25.168/api/sales-app/order-management-data-by-salesperson?page=1",
"from": 1,
"last_page": 1,
"last_page_url": "http://23.101.25.168/api/sales-app/order-management-data-by-salesperson?page=1",
"next_page_url": null,
"path": "http://23.101.25.168/api/sales-app/order-management-data-by-salesperson",
"per_page": 20,
"prev_page_url": null,
"to": 1,
"total": 1
}
}

OrderListModel.java

public class OrderListModel {
@SerializedName("current_page")
@Expose
private Integer currentPage;
@SerializedName("data")
@Expose
private List<OrderListResponse> data = null;
@SerializedName("first_page_url")
@Expose
private String firstPageUrl;
@SerializedName("from")
@Expose
private Integer from;
@SerializedName("last_page")
@Expose
private Integer lastPage;
@SerializedName("last_page_url")
@Expose
private String lastPageUrl;
@SerializedName("next_page_url")
@Expose
private Object nextPageUrl;
@SerializedName("path")
@Expose
private String path;
@SerializedName("per_page")
@Expose
private Integer perPage;
@SerializedName("prev_page_url")
@Expose
private Object prevPageUrl;
@SerializedName("to")
@Expose
private Integer to;
@SerializedName("total")
@Expose
private Integer total;

public Integer getCurrentPage() {
return currentPage;
}

public void setCurrentPage(Integer currentPage) {
this.currentPage = currentPage;
}

public List<OrderListResponse> getData() {
return data;
}

public void setData(List<OrderListResponse> data) {
this.data = data;
}

public String getFirstPageUrl() {
return firstPageUrl;
}

public void setFirstPageUrl(String firstPageUrl) {
this.firstPageUrl = firstPageUrl;
}

public Integer getFrom() {
return from;
}

public void setFrom(Integer from) {
this.from = from;
}

public Integer getLastPage() {
return lastPage;
}

public void setLastPage(Integer lastPage) {
this.lastPage = lastPage;
}

public String getLastPageUrl() {
return lastPageUrl;
}

public void setLastPageUrl(String lastPageUrl) {
this.lastPageUrl = lastPageUrl;
}

public Object getNextPageUrl() {
return nextPageUrl;
}

public void setNextPageUrl(Object nextPageUrl) {
this.nextPageUrl = nextPageUrl;
}

public String getPath() {
return path;
}

public void setPath(String path) {
this.path = path;
}

public Integer getPerPage() {
return perPage;
}

public void setPerPage(Integer perPage) {
this.perPage = perPage;
}

public Object getPrevPageUrl() {
return prevPageUrl;
}

public void setPrevPageUrl(Object prevPageUrl) {
this.prevPageUrl = prevPageUrl;
}

public Integer getTo() {
return to;
}

public void setTo(Integer to) {
this.to = to;
}

public Integer getTotal() {
return total;
}

public void setTotal(Integer total) {
this.total = total;
}
}

OrderListResponse.java

public class OrderListResponse {
@SerializedName("mokita_transact_id")
@Expose
private Integer mokitaTransactId;
@SerializedName("diab_transact_id")
@Expose
private String diabTransactId;
@SerializedName("order_status")
@Expose
private String orderStatus;
@SerializedName("leasing_status")
@Expose
private String leasingStatus;
@SerializedName("id_card_num")
@Expose
private String idCardNum;
@SerializedName("hot_leads_id")
@Expose
private Integer hotLeadsId;
@SerializedName("qty")
@Expose
private Integer qty;
@SerializedName("retail_dealer_id")
@Expose
private Integer retailDealerId;
@SerializedName("rd_code")
@Expose
private String rdCode;
@SerializedName("customer_name")
@Expose
private String customerName;
@SerializedName("birthdate")
@Expose
private String birthdate;
@SerializedName("gender")
@Expose
private Integer gender;
@SerializedName("address")
@Expose
private String address;
@SerializedName("kelurahan_id")
@Expose
private Integer kelurahanId;
@SerializedName("kelurahan")
@Expose
private String kelurahan;
@SerializedName("kecamatan_id")
@Expose
private Integer kecamatanId;
@SerializedName("kecamatan")
@Expose
private String kecamatan;
@SerializedName("customer_number")
@Expose
private String customerNumber;
@SerializedName("kota_id")
@Expose
private Integer kotaId;
@SerializedName("kota")
@Expose
private Integer kota;
@SerializedName("postal_code")
@Expose
private Integer postalCode;
@SerializedName("payment_option_id")
@Expose
private Integer paymentOptionId;
@SerializedName("payment_type")
@Expose
private String paymentType;
@SerializedName("datetime")
@Expose
private String datetime;
@SerializedName("product_variant_id")
@Expose
private Integer productVariantId;
@SerializedName("model_code")
@Expose
private String modelCode;
@SerializedName("color_code")
@Expose
private String colorCode;
@SerializedName("credit_provider_id")
@Expose
private Integer creditProviderId;
@SerializedName("dp")
@Expose
private Integer dp;
@SerializedName("credit_term_id")
@Expose
private Integer creditTermId;
@SerializedName("credit_term")
@Expose
private Integer creditTerm;
@SerializedName("monthly_installment")
@Expose
private Integer monthlyInstallment;
@SerializedName("sales_people_id")
@Expose
private String salesPeopleId;
@SerializedName("spk_number")
@Expose
private Integer spkNumber;
@SerializedName("is_indent")
@Expose
private Integer isIndent;
@SerializedName("hot_leads")
@Expose
private HotLeadsResponse hotLeads;
@SerializedName("payment_detail")
@Expose
private PaymentDetailResponse paymentDetail;
@SerializedName("product_variant_motor")
@Expose
private ProductVariantResponse productVariantMotor;

public Integer getMokitaTransactId() {
return mokitaTransactId;
}

public void setMokitaTransactId(Integer mokitaTransactId) {
this.mokitaTransactId = mokitaTransactId;
}

public String getDiabTransactId() {
return diabTransactId;
}

public void setDiabTransactId(String diabTransactId) {
this.diabTransactId = diabTransactId;
}

public String getOrderStatus() {
return orderStatus;
}

public void setOrderStatus(String orderStatus) {
this.orderStatus = orderStatus;
}

public String getLeasingStatus() {
return leasingStatus;
}

public void setLeasingStatus(String leasingStatus) {
this.leasingStatus = leasingStatus;
}

public String getIdCardNum() {
return idCardNum;
}

public void setIdCardNum(String idCardNum) {
this.idCardNum = idCardNum;
}

public Integer getHotLeadsId() {
return hotLeadsId;
}

public void setHotLeadsId(Integer hotLeadsId) {
this.hotLeadsId = hotLeadsId;
}

public Integer getQty() {
return qty;
}

public void setQty(Integer qty) {
this.qty = qty;
}

public Integer getRetailDealerId() {
return retailDealerId;
}

public void setRetailDealerId(Integer retailDealerId) {
this.retailDealerId = retailDealerId;
}

public String getRdCode() {
return rdCode;
}

public void setRdCode(String rdCode) {
this.rdCode = rdCode;
}

public String getCustomerName() {
return customerName;
}

public void setCustomerName(String customerName) {
this.customerName = customerName;
}

public String getBirthdate() {
return birthdate;
}

public void setBirthdate(String birthdate) {
this.birthdate = birthdate;
}

public Integer getGender() {
return gender;
}

public void setGender(Integer gender) {
this.gender = gender;
}

public String getAddress() {
return address;
}

public void setAddress(String address) {
this.address = address;
}

public Integer getKelurahanId() {
return kelurahanId;
}

public void setKelurahanId(Integer kelurahanId) {
this.kelurahanId = kelurahanId;
}

public String getKelurahan() {
return kelurahan;
}

public void setKelurahan(String kelurahan) {
this.kelurahan = kelurahan;
}

public Integer getKecamatanId() {
return kecamatanId;
}

public void setKecamatanId(Integer kecamatanId) {
this.kecamatanId = kecamatanId;
}

public String getKecamatan() {
return kecamatan;
}

public void setKecamatan(String kecamatan) {
this.kecamatan = kecamatan;
}

public String getCustomerNumber() {
return customerNumber;
}

public void setCustomerNumber(String customerNumber) {
this.customerNumber = customerNumber;
}

public Integer getKotaId() {
return kotaId;
}

public void setKotaId(Integer kotaId) {
this.kotaId = kotaId;
}

public Integer getKota() {
return kota;
}

public void setKota(Integer kota) {
this.kota = kota;
}

public Integer getPostalCode() {
return postalCode;
}

public void setPostalCode(Integer postalCode) {
this.postalCode = postalCode;
}

public Integer getPaymentOptionId() {
return paymentOptionId;
}

public void setPaymentOptionId(Integer paymentOptionId) {
this.paymentOptionId = paymentOptionId;
}

public String getPaymentType() {
return paymentType;
}

public void setPaymentType(String paymentType) {
this.paymentType = paymentType;
}

public String getDatetime() {
return datetime;
}

public void setDatetime(String datetime) {
this.datetime = datetime;
}

public Integer getProductVariantId() {
return productVariantId;
}

public void setProductVariantId(Integer productVariantId) {
this.productVariantId = productVariantId;
}

public String getModelCode() {
return modelCode;
}

public void setModelCode(String modelCode) {
this.modelCode = modelCode;
}

public String getColorCode() {
return colorCode;
}

public void setColorCode(String colorCode) {
this.colorCode = colorCode;
}

public Integer getCreditProviderId() {
return creditProviderId;
}

public void setCreditProviderId(Integer creditProviderId) {
this.creditProviderId = creditProviderId;
}

public Integer getDp() {
return dp;
}

public void setDp(Integer dp) {
this.dp = dp;
}

public Integer getCreditTermId() {
return creditTermId;
}

public void setCreditTermId(Integer creditTermId) {
this.creditTermId = creditTermId;
}

public Integer getCreditTerm() {
return creditTerm;
}

public void setCreditTerm(Integer creditTerm) {
this.creditTerm = creditTerm;
}

public Integer getMonthlyInstallment() {
return monthlyInstallment;
}

public void setMonthlyInstallment(Integer monthlyInstallment) {
this.monthlyInstallment = monthlyInstallment;
}

public String getSalesPeopleId() {
return salesPeopleId;
}

public void setSalesPeopleId(String salesPeopleId) {
this.salesPeopleId = salesPeopleId;
}

public Integer getSpkNumber() {
return spkNumber;
}

public void setSpkNumber(Integer spkNumber) {
this.spkNumber = spkNumber;
}

public Integer getIsIndent() {
return isIndent;
}

public void setIsIndent(Integer isIndent) {
this.isIndent = isIndent;
}

public HotLeadsResponse getHotLeads() {
return hotLeads;
}

public void setHotLeads(HotLeadsResponse hotLeads) {
this.hotLeads = hotLeads;
}

public PaymentDetailResponse getPaymentDetail() {
return paymentDetail;
}

public void setPaymentDetail(PaymentDetailResponse paymentDetail) {
this.paymentDetail = paymentDetail;
}

public ProductVariantResponse getProductVariantMotor() {
return productVariantMotor;
}

public void setProductVariantMotor(ProductVariantResponse productVariantMotor) {
this.productVariantMotor = productVariantMotor;
}

}

OrderListingAdapter.java

public class OrderListingAdapter extends RecyclerView.Adapter<OrderListingAdapter.OrderListingViewHolder> {

private List<OrderListResponse> customerName;

public OrderListingAdapter(List<OrderListResponse> customerName) {
this.customerName = customerName;
}


@Override
public OrderListingViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View layoutView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.item_order_lists, null);

OrderListingViewHolder recyclerViewHolder = new OrderListingViewHolder(layoutView);

return recyclerViewHolder;
}

@Override
public void onBindViewHolder(OrderListingViewHolder holder, int position) {
holder.txtCustomerName.setText(customerName.get(position).getCustomerName());
holder.txtMotorName.setText(customerName.get(position).getProductVariantMotor().getType());
}

@Override
public int getItemCount() {
return customerName.size();
}

class OrderListingViewHolder extends RecyclerView.ViewHolder {

TextView txtCustomerName, txtMotorName;

OrderListingViewHolder(View itemView) {
super(itemView);
txtCustomerName = (TextView) itemView.findViewById(R.id.textViewCustomerName);
txtMotorName = (TextView) itemView.findViewById(R.id.textViewMotor);
}
}

}

OrderListingFragment.java

public class OrderListingFragment extends Fragment {
View v;
private OrderListingAdapter adapter;
private RecyclerView recyclerView;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
v = inflater.inflate(R.layout.fragment_order_listing, container, false);

// JsonObject jsonObject = new JsonObject();
// jsonObject.addProperty("sales_people_id",14);
ApiInterface service = ApiClient.getClient().create(ApiInterface.class);
Call<OrderListModel> call = service.getOrderList("14");

call.enqueue(new Callback<OrderListModel>() {
@Override
public void onResponse(Call <OrderListModel> call, Response<OrderListModel> response) {
try {
if (response.code() == 200) {
Log.e("RECYCLER",""+response.body());
generateEmployeeList(response.body().getData());
} else {
Log.e("ERROR CODE", "" + response.code());
Log.e("Error Message", "" + response.errorBody());
}

} catch (Exception e) {
e.printStackTrace();
}
}

@Override
public void onFailure(Call<OrderListModel> call, Throwable t) {
Log.e("response-failure-coy", call.toString());
t.printStackTrace();
Log.e("Error Kims",""+t.getMessage());
}
});
return v;
}
private void generateEmployeeList(List<OrderListResponse> empDataList) {
recyclerView = (RecyclerView) v.findViewById(R.id.recyclerOrderList);

adapter = new OrderListingAdapter(empDataList);

RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(v.getContext());

recyclerView.setLayoutManager(layoutManager);

recyclerView.setAdapter(adapter);
}
}

我该如何解决这个错误?提前致谢。

最佳答案

您的 OrderListModel 类与您获得的 JSON 响应不匹配。您期望最外层对象具有诸如 current_pagedatafirst_page_url 之类的属性。这些属性是响应的一部分,但它们嵌套在另一个对象中。

所以你需要一个额外的类:

public class OrderResponse {
@SerializedName("code")
@Expose
private Integer code;

@SerializedName("status")
@Expose
private String status;

@SerializedName("data")
@Expose
private OrderListModel data;

...

界面变成:

@FormUrlEncoded
@POST("order-management-data-by-salesperson")
Call<OrderResponse> getOrderList(@Field("sales_people_id") String salesPeopleId);

其余代码需要进一步更改...

关于java - 应为 BEGIN_ARRAY,但在第 1 行第 53 列路径 $.data 处为 BEGIN_OBJECT,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53580822/

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