【问题标题】:How to parse a complex ksoap Object to String on Android?如何在 Android 上将复杂的 ksoap 对象解析为字符串?
【发布时间】:2016-03-22 21:27:45
【问题描述】:

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

如图所示只是工作“答案”。 我怎样才能得到“最后一个”?

【问题讨论】:

    标签: android ksoap2 android-ksoap2 ksoap


    【解决方案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");
    

    希望对你有帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-03-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多