代码之家  ›  专栏  ›  技术社区  ›  Rodrick

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

  •  0
  • Rodrick  · 技术社区  · 9 年前

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

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

    1 回复  |  直到 9 年前
        1
  •  1
  •   Mithun Mahendra Chhimwal    9 年前

    你能试一下吗

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

    希望有帮助!