KSOAP 2复杂类

时间:2012-07-08 19:32:14

标签: android ksoap

我需要在里面发送带有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);

OrderItem&gt;

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;
    }
}

OrderItemList&gt;

public class OrderItemList {
    public ArrayList<OrderItem> OrderItemList;

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

1 个答案:

答案 0 :(得分: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;
    }
}