首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在安卓系统中分析KSOAP2响应?

如何在安卓系统中分析KSOAP2响应?
EN

Stack Overflow用户
提问于 2012-03-29 04:53:18
回答 2查看 9.9K关注 0票数 1

我在Android中使用KSoap2调用了一个webservice,但我得到的响应如下。如何在Android中解析这个ksoap响应?

发现了ResolveNamesResponse{ResponseMessages=anyType{ResolveNamesResponseMessage=anyType{MessageText=Multiple结果;ResponseCode=ErrorNameResolutionMultipleResults;DescriptiveLinkKey=0;ResolutionSet=anyType{Resolution=anyType{Mailbox=anyType{Name=Amyj;EmailAddress=Amyj@testsa.onmicrosoft.com;RoutingType=SMTP;MailboxType=Mailbox;};Contact=anyType{DisplayName=Amy John;GivenName=Amy;EmailAddresses=anyType{Entry=SIP:Amyj@test.onmicrosoft.com;Entry=SMTP:Amyj@testsa.onmicrosoft.com;};ContactSource=ActiveDirectory;Surname=John;};};PhysicalAddresses=anyType{Entry=anyType{CountryOrRegion=China;;EmailAddresses=anyType{Entry=SIP:Amyraj@testsa.onmicrosoft.com;Entry=SMTP:Amyraj@testsa.onmicrosoft.com;};PhysicalAddresses=anyType{Entry=anyType{CountryOrRegion=India;};};ContactSource=ActiveDirectory;Surname=Raj;};};Resolution=anyType{Mailbox=anyType{Name=shine;EmailAddress=shine@testsa.onmicrosoft.com;RoutingType=SMTP;MailboxType=Mailbox;};PhysicalAddresses=anyType{Entry=anyType{CountryOrRegion=India;};};ContactSource=ActiveDirectory;Surname=Joseph;};};

EN

回答 2

Stack Overflow用户

发布于 2014-08-28 08:28:14

试试这个,我想它会起作用的

代码语言:javascript
复制
SoapObject response = (SoapObject) envelope.getResponse();

int cols = response.getPropertyCount();

for (int i = 0; i < cols; i++) {

    Object objectResponse = (Object) response.getProperty(i);
    SoapObject r =(SoapObject) objectResponse;

    String   key1=(String) r.getProperty("key1").toString();

    // Get the rest of your Properties by 
    // (String) r.getProperty("PropertyName").toString();            
}
票数 1
EN

Stack Overflow用户

发布于 2012-03-29 06:48:12

实际上,这是一种已知的格式,如果您知道Java Script.这种格式的数据实际上是JSON Object's and JSON Array's.So,这里是如何解析这个结果的。

例:

代码语言:javascript
复制
private Bundle bundleResult=new Bundle();
private JSONObject JSONObj;
private JSONArray JSONArr;
Private SoapObject resultSOAP = (SoapObject) envelope.getResponse();
/* gets our result in JSON String */
private String ResultObject = resultSOAP.getProperty(0).toString();

if (ResultObject.startsWith("{")) { // if JSON string is an object
    JSONObj = new JSONObject(ResultObject);
    Iterator<String> itr = JSONObj.keys();
    while (itr.hasNext()) {
        String Key = (String) itr.next();
        String Value = JSONObj.getString(Key);
        bundleResult.putString(Key, Value);
        // System.out.println(bundleResult.getString(Key));
    }
} else if (ResultObject.startsWith("[")) { // if JSON string is an array
    JSONArr = new JSONArray(ResultObject);
    System.out.println("length" + JSONArr.length());
    for (int i = 0; i < JSONArr.length(); i++) {
        JSONObj = (JSONObject) JSONArr.get(i);
        bundleResult.putString(String.valueOf(i), JSONObj.toString());
        // System.out.println(bundleResult.getString(i));
    } 
}

我希望这能帮你解决问题。

票数 -2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/9919256

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档