2

我需要在里面发送带有 OrderItem 类数组的 OrderItemList 类,我尝试了这个但给了我错误。无法序列化:foo.foo.OrderItemList@461e0bf8

提前感谢您的时间。

SoapObject request = new SoapObject(NAMESPACE, WebService);
        OrderItemList orderItemList = null;

            PropertyInfo pinfo = new PropertyInfo();
            pinfo.name = "orderItems";
            pinfo.namespace = NAMESPACE ;
            pinfo.type = OrderItemList.class;

            ArrayList<OrderItem> orderItemListT = new ArrayList<OrderItem>();
            orderItemListT.add(new OrderItem(9,9,"",9,9,9,9));
            orderItemList = new OrderItemList(orderItemListT);

            request.addProperty(pinfo,orderItemList);

    SoapSerializationEnvelope envelope =
        new SoapSerializationEnvelope(SoapEnvelope.VER11);
    envelope.addMapping(NAMESPACE, "orderItems", orderItemList.getClass());
    envelope.addMapping(NAMESPACE, "OrderItem", OrderItem.class); 
    envelope.dotNet = true;
    envelope.setOutputSoapObject(request); 
    AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL);

    androidHttpTransport.call("http://tempuri.org/" + WebService , envelope);

订单项 >

public class OrderItem {
    public int ID;
    public int OrderId;
    public String FinalCode;
    public int Quantity;
    public double Price;
    public double Discount;
    public int Status;

    public OrderItem(int id, int orderId, String finalCode ,int quantity, double price, double discount, int status) {
    ID = id;
    OrderId = orderId;
    FinalCode = finalCode;
    Quantity = quantity;
    Price = price;
    Discount = discount;
        Status = status;
    }
}

订单项列表 >

public class OrderItemList {
    public ArrayList<OrderItem> OrderItemList;

    public OrderItemList(ArrayList<OrderItem> orderItemList) {
        OrderItemList = orderItemList;
    }
}
4

1 回答 1

2

在你的类中实现 Serializable

import java.io.Serializable;

public class OrderItem implements Serializable {
    public int ID;
    public int OrderId;
    public String FinalCode;
    public int Quantity;
    public double Price;
    public double Discount;
    public int Status;

    public OrderItem(int id, int orderId, String finalCode ,int quantity, double price, double discount, int status) {
        ID = id;
        OrderId = orderId;
        FinalCode = finalCode;
        Quantity = quantity;
        Price = price;
        Discount = discount;
        Status = status;
    }
}
于 2012-12-04T16:28:38.900 回答