如何在 Android 上将复杂的 ksoap 对象解析为字符串?

How to parse a complex ksoap Object to String on Android?

我正在使用 KSOAP2 (3.0.0) 得到如下响应:

    <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" >
        <env:Header>
        </env:Header>
        <env:Body>
            <ns2:ExampleResponse xmlns:ns2="http://example.com/" >
                <result>
                    <answer>0</answer>
                    <message>
                        <last>0</last>
                    </message>
                </result>
            </ns2:ExampleResponse>
        </env:Body>
    </env:Envelope>

我想捕获“最后,我使用了以下内容:

String ans1 = response.getPropertyAsString("answer"); // 0
String ans2 = response.getPropertyAsString("message"); // anyType{last=0; }
String ans3 = response.getPropertyAsString("last"); // illegal property: last

如图所示,正常工作 "answer"。 我怎样才能得到"last"?

您可以尝试以下操作吗:

// Fetches message as soap object, rather than just its string representation
SoapObject messageObject = (SoapObject) response.getProperty("message");

// Fetches last from above oject
String lastAsString = messageObject.getPropertyAsString("last");

希望对您有所帮助!