what I am having here is a web service that gives me the following JSON code :
[
{
"_OrderDetails": [
{
"ProductName": "FUCHS SUPER GT SAE 10W30 6X5 / FP10100010102",
"TotalAfterDiscount_Lc": "7500",
"MeasureUnitName": "??????",
"TotalPrice_Lc": "7500",
"PricePerUnit_Lc": "75",
"Quantity": "100"
}
],
"Id": "274",
"OrderDate": "4/10/2014 12:00:00 AM",
"Number": "16",
"CustomerName": "?????",
"Note": ""
}
]
and I have made a java class (entity) with getters and setters for all data :
package com.example.webservicetest;
import java.util.List;
public class Item {
private String OrderDate;
private String Number;
private String Note;
private String CustomerName;
private String Id;
private List<_OrderDetails> orderDetails;
public String getOrderDate() {
return OrderDate;
}
public void setOrderDate(String orderDate) {
OrderDate = orderDate;
}
public String getNumber() {
return Number;
}
public void setNumber(String number) {
Number = number;
}
public String getNote() {
return Note;
}
public void setNote(String note) {
Note = note;
}
public String getId() {
return Id;
}
public void setId(String id) {
Id = id;
}
public String getCustomerName() {
return CustomerName;
}
public void setCustomerName(String customerName) {
CustomerName = customerName;
}
public List<_OrderDetails> getOrderDetails() {
return orderDetails;
}
public void setOrderDetails(List<_OrderDetails> orderDetails) {
this.orderDetails = orderDetails;
}
public class _OrderDetails{
private String OrderId;
private String OrderDate;
private String Number;
private String Note;
private String ProductName;
private String TotalAfterDiscount_Lc;
private String MeasureUnitName;
private String TotalPrice_Lc;
private String PricePerUnit_Lc;
private String Quantity;
public String getOrderId() {
return OrderId;
}
public void setOrderId(String orderId) {
OrderId = orderId;
}
public String getOrderDate() {
return OrderDate;
}
public void setOrderDate(String orderDate) {
OrderDate = orderDate;
}
public String getNumber() {
return Number;
}
public void setNumber(String number) {
Number = number;
}
public String getNote() {
return Note;
}
public void setNote(String note) {
Note = note;
}
public String getProductName() {
return ProductName;
}
public void setProductName(String productName) {
ProductName = productName;
}
public String getTotalAfterDiscount_Lc() {
return TotalAfterDiscount_Lc;
}
public void setTotalAfterDiscount_Lc(String totalAfterDiscount_Lc) {
TotalAfterDiscount_Lc = totalAfterDiscount_Lc;
}
public String getMeasureUnitName() {
return MeasureUnitName;
}
public void setMeasureUnitName(String measureUnitName) {
MeasureUnitName = measureUnitName;
}
public String getTotalPrice_Lc() {
return TotalPrice_Lc;
}
public void setTotalPrice_Lc(String totalPrice_Lc) {
TotalPrice_Lc = totalPrice_Lc;
}
public String getPricePerUnit_Lc() {
return PricePerUnit_Lc;
}
public void setPricePerUnit_Lc(String pricePerUnit_Lc) {
PricePerUnit_Lc = pricePerUnit_Lc;
}
public String getQuantity() {
return Quantity;
}
public void setQuantity(String quantity) {
Quantity = quantity;
}
}
}
and in the main activity I get the data like this:
Item[] placelist;
placelist = gson.fromJson(responseJSON, Item[].class);
Item item = gson.fromJson(responseJSON, Item.class);
but I get in the logcat the following exception :
Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
please what am I doing wrong???
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…