什麼我有在這裏是給我下面的JSON代碼Web服務:預計BEGIN_OBJECT但BEGIN_ARRAY位於第1行第2列(小編輯)
[
{
"_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": ""
}
]
和我進行了一個Java類(實體)與getter和setter的所有數據:
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;
}
}
}
,並在主要活動我得到這樣的數據:
Item[] placelist;
placelist = gson.fromJson(responseJSON, Item[].class);
Item item = gson.fromJson(responseJSON, Item.class);
但我得到了logcat以下例外: Expected BEGIN_OBJECT but was BEGIN_ARRAY at line 1 column 2
請問我在做什麼錯?
所以你可以編輯它?因爲我是新的Android和JSON – user3534834