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/recoming_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 に答える