Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/hibernate/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:如何将SoapObject反序列化为复杂对象-KSOAP2_Android_Soap_Deserialization_Ksoap2 - Fatal编程技术网

Android:如何将SoapObject反序列化为复杂对象-KSOAP2

Android:如何将SoapObject反序列化为复杂对象-KSOAP2,android,soap,deserialization,ksoap2,Android,Soap,Deserialization,Ksoap2,我正在尝试将SoapRequest反序列化到复杂对象。以下是XML响应: <ArrayOfECar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://testing.com/"> <eCar> <Id>1</Id> <Descri

我正在尝试将SoapRequest反序列化到复杂对象。以下是XML响应:

<ArrayOfECar xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://testing.com/">
    <eCar>
        <Id>1</Id>
        <Description>Fiat</Description>
        <Drivers>
            <eDriver>
                <Id>1</Id>
                <Description>Lucas</Description>
            </eDriver>
            <eDriver>
                <Id>2</Id>
                <Description>John</Description>
            </eDriver>
        </Drivers>
    </eCar>
    <eCar>
        <Id>2</Id>
        <Description>Ford</Description>
        <Drivers>
            <eDriver>
                <Id>1</Id>
                <Description>Charly</Description>
            </eDriver>
            <eDriver>
                <Id>2</Id>
                <Description>Harry</Description>
            </eDriver>
        </Drivers>
    </eCar>
</ArrayOfECar>
驾驶员等级:

public class Driver implements KvmSerializable {
    private int id;
    private String description;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public Object getProperty(int index) {
        switch (index) {
            case 0:
                return getId();
            case 1:
                return getDescription();
        }
        return null;
    }

    @Override
    public int getPropertyCount() {
        return 2;
    }

    @Override
    public void setProperty(int index, Object value) {
        switch (index) {
            case 0:
                setId(Integer.parseInt(value.toString()));
                break;
            case 1:
                setDescription(value.toString());
                break;
            default:
                break;
        }
    }

    @Override
    public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) {
        switch (index) {
            case 0:
                info.name = "Id";
                info.type = PropertyInfo.INTEGER_CLASS;
                break;
            case 1:
                info.name = "Description";
                info.type = PropertyInfo.STRING_CLASS;
                break;
            default:
                break;
        }
    }
}
public class ArrayDriver extends Vector<Driver> implements KvmSerializable {

    @Override
    public Object getProperty(int index) {
        return this.get(index);
    }

    @Override
    public int getPropertyCount() {
        return this.size();
    }

    @Override
    public void setProperty(int index, Object value) {
        this.add((Driver)value);
    }

    @Override
    public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) {
        info.name = "eDriver";
        info.type = Driver.class;
    }
}
和这样的阵列:

ArrayCar类别:

public class Car implements KvmSerializable {
    private int id;
    private String description;
    private ArrayDriver drivers;

    public int getId() {
        return id;
    }
    public void setId(int id) {
        this.id = id;
    }
    public String getDescription() {
        return description;
    }
    public void setDescription(String description) {
        this.description = description;
    }
    public ArrayDriver getDrivers() {
        return drivers;
    }
    public void setDrivers(ArrayDriver drivers) {
        this.drivers = drivers;
    }

    @Override
    public Object getProperty(int index) {
        switch (index) {
            case 0:
                return getId();
            case 1:
                return getDescription();
            case 2:
                return getDrivers();
        }
        return null;
    }

    @Override
    public int getPropertyCount() {
        return 3;
    }

    @Override
    public void setProperty(int index, Object value) {
        switch (index) {
            case 0:
                setId(Integer.parseInt(value.toString()));
                break;
            case 1:
                setDescription(value.toString());
                break;
            case 2:
                setDrivers((ArrayDriver)value);
                break;
            default:
                break;
        }
    }

    @Override
    public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) {
        switch (index) {
            case 0:
                info.name = "Id";
                info.type = PropertyInfo.INTEGER_CLASS;
                break;
            case 1:
                info.name = "Description";
                info.type = PropertyInfo.STRING_CLASS;
                break;
            case 2:
                info.name = "Drivers";
                info.type = ArrayDriver.class;
                break;
            default:
                break;
        }
    }
}
public class ArrayCar extends Vector<Car> implements KvmSerializable {

    @Override
    public Object getProperty(int index) {
        return this.get(index);
    }

    @Override
    public int getPropertyCount() {
        return this.size();
    }

    @Override
    public void setProperty(int index, Object value) {
        this.add((Car)value);
    }

    @Override
    public void getPropertyInfo(int index, Hashtable properties, PropertyInfo info) {
        info.name = "eCar";
        info.type = Car.class;
    }
}
但它不起作用,抛出此异常:

java.lang.ClassCastException: org.ksoap2.serialization.SoapObject cannot be cast to com.oseas.wsconsumer.entities.ArrayCar
我知道我可以手动反序列化它,按SoapObject中的每个属性循环,等等。但是我想知道是否有一种方法可以使它更简单、更自动化

对不起,英语不好,希望你能理解

java.lang.ClassCastException: org.ksoap2.serialization.SoapObject cannot be cast to com.oseas.wsconsumer.entities.ArrayCar