1

SOAP 响应

<?xml version="1.0" encoding="UTF-8"?>
 <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
    <S:Body>
    <ns2:getItemTypesResponse xmlns:ns2="http://Product/">
        <return>Laptop</return>
        <return>Netbook</return>
    </ns2:getItemTypesResponse>
</S:Body>

如何在 android 中解析这个 SOAP 响应?

这是我的代码。

for(int i =0 ; i<count;i++){
            //SoapObject inner= (SoapObject)outer.getProperty(i);
            String s = null;
            s = outer.getProperty(i).toString();
            result.add(s);
        }
4

2 回答 2

1

您所需要的都在这里:http
://code.google.com/p/ksoap2-android/wiki/CodingTipsAndTricks#sending/receiving_array_of_complex_types_or_primitives尝试创建对象实现KvmSerializable

于 2012-10-16T09:41:22.347 回答
1

创建一个实现的类KvmSerializeable

public class Import implements KvmSerializable {

String test;

public Import() {}

public Import (String test) {
    this.test = test;
}

public Object getProperty(int arg0) {

    switch (arg0) {

    case 0:
        return test;
    default:
        return test;
    }

}

public int getPropertyCount() {
    return 1;
}

public void getPropertyInfo(int arg0, Hashtable arg1, PropertyInfo arg2) {

    switch (arg0) {
    case 0:
        arg2.type = PropertyInfo.STRING_CLASS;
        arg2.name = "test";
        break;
    default:
        break;
    }

}

public void setProperty(int arg0, Object arg1) {

    switch (arg0) {
    case 0:
        test = (String) arg1;
        break;
    }

}

}

只需更改变量,使其适合您的需要。进而:

        SoapObject soapObject = new SoapObject(NAMESPACE_NIST_IMPORT,
                METHOD_NAME_NIST_IMPORT);

       Import import= new Import("Hello, World!");

        PropertyInfo pi = new PropertyInfo();
        pi.setName("req");
        pi.setValue(import);
        pi.setType(import.getClass());
        soapObject.addProperty(pi);


        SoapSerializationEnvelope soapSerializationEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);

        soapSerializationEnvelope.setOutputSoapObject(soapObject);

        soapSerializationEnvelope.addMapping(NAMESPACE, "Import", new Import().getClass());

要解析响应:

        SoapObject response = (SoapObject)soapSerializationEnvelope.getResponse();
        Import.test=  response.getProperty(0).toString();
于 2012-10-16T10:08:22.563 回答