我所拥有的是一个asp web服务,它为我调用以下JSON代码:
[
{
"_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类):
public class Item implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@SerializedName("_OrderDetails")
private OrderDetails[] mOrderDetails;
@SerializedName("Id")
private String mId;
@SerializedName("OrderData")
private String mOrderDate;
@SerializedName("Number")
private String mNumber;
@SerializedName("CustomerName")
private String mCustomerName;
@SerializedName("Note")
private String mNote;
// Add setters and getters
public String getOrderDate() {
return mOrderDate;
}
public void setOrderDate(String orderDate) {
mOrderDate = orderDate;
}
public String getNumber() {
return mNumber;
}
public void setNumber(String number) {
mNumber = number;
}
public String getNote() {
return mNote;
}
public void setNote(String note) {
mNote = note;
}
public String getId() {
return mId;
}
public void setId(String id) {
mId = id;
}
public String getCustomerName() {
return mCustomerName;
}
public void setCustomerName(String customerName) {
mCustomerName = customerName;
}
public static class OrderDetails implements Serializable {
/**
*
*/
private static final long serialVersionUID = 1L;
@SerializedName("ProductName")
private String mProductName;
@SerializedName("TotalAfterDiscount_Lc")
private String mTotalAfterDiscount;
@SerializedName("MeasureUnitName")
private String mMeasureUnitName;
@SerializedName("TotalPrice_Lc")
private String mTotalPrice;
@SerializedName("PricePerUnit_Lc")
private String mPricePerUnit;
@SerializedName("Quantity")
private String mQuantity;
// Add setters and getters
public String getProductName() {
return mProductName;
}
public void setProductName(String productName) {
mProductName = productName;
}
public String getTotalAfterDiscount_Lc() {
return mTotalAfterDiscount;
}
public void setTotalAfterDiscount_Lc(String totalAfterDiscount_Lc) {
mTotalAfterDiscount = totalAfterDiscount_Lc;
}
public String getMeasureUnitName() {
return mMeasureUnitName;
}
public void setMeasureUnitName(String measureUnitName) {
mMeasureUnitName = measureUnitName;
}
public String getTotalPrice_Lc() {
return mTotalPrice;
}
public void setTotalPrice_Lc(String totalPrice_Lc) {
mTotalPrice = totalPrice_Lc;
}
public String getPricePerUnit_Lc() {
return mPricePerUnit;
}
public void setPricePerUnit_Lc(String pricePerUnit_Lc) {
mPricePerUnit = pricePerUnit_Lc;
}
public String getQuantity() {
return mQuantity;
}
public void setQuantity(String quantity) {
mQuantity = quantity;
}
}
并在主要活动中:
Gson gson = new Gson();
Item[] items = new Gson().fromJson(responseJSON, Item[].class);
String date=items[0].getOrderDate();
Log.e("data",date+"");
但它给了我!在logcat所以请谁能告诉我我做错了什么?
答案 0 :(得分:0)
我认为您创建的Java类中存在映射JSON属性的问题。我也有类似的问题,我偶然发现了这个很棒的答案。
Java Json program not showing any output
看看它并希望它有所帮助!