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

时间:2016-03-22 21:27:45

标签: android ksoap2 android-ksoap2 ksoap

我正在使用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>

我想捕获&#34;最后,我使用了以下内容:

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

如图所示只是工作&#34;回答&#34;。 我怎样才能获得&#34;最后&#34;?

1 个答案:

答案 0 :(得分:1)

你能尝试一下:

// 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");

希望它有所帮助!