1

I called a webservice using KSoap2 in Android, but the response I got is as follows. How to parse this ksoap response in Android?

ResolveNamesResponse{ResponseMessages=anyType{ResolveNamesResponseMessage=anyType{MessageText=Multiple results were found.; 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; }; PhysicalAddresses=anyType{Entry=anyType{CountryOrRegion=China; }; }; ContactSource=ActiveDirectory; Surname=John; }; }; Resolution=anyType{Mailbox=anyType{Name=Amyraj; EmailAddress=Amyraj@testsa.onmicrosoft.com; RoutingType=SMTP; MailboxType=Mailbox; }; Contact=anyType{DisplayName=Amy Raj; GivenName=Amy; 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; }; Contact=anyType{DisplayName=Shine Joseph; GivenName=Shine; EmailAddresses=anyType{Entry=SIP:shine@testsa.onmicrosoft.com; Entry=SMTP:shine@testsa.onmicrosoft.com; }; PhysicalAddresses=anyType{Entry=anyType{CountryOrRegion=India; }; }; ContactSource=ActiveDirectory; Surname=Joseph; }; }; }; }; }; }

halfer
  • 19,824
  • 17
  • 99
  • 186
jennifer
  • 8,133
  • 22
  • 69
  • 96

2 Answers2

1

Try This I think it will work

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();            
}
dream3r
  • 11
  • 5
Wais
  • 1,739
  • 1
  • 13
  • 13
-2

Actually this a known format if you know Java Script. These data in this format are infact JSON Object's and JSON Array's.So here is how you can parse this result.

eg:

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));
    } 
}

I hope this helps you solve your problem.

MorningGlory
  • 758
  • 1
  • 11
  • 21