2012-03-29 3 views
1

나는 KSoap2 in android을 사용하여 webservice를 호출하지만, 내가 가진 응답은 다음과 같습니다. android에서이 ksoap 응답을 구문 분석하는 방법.안드로이드 : 어떻게 KSOAP2 응답을 구문 분석

ResolveNamesResponse {ResponseMessages = anyType에 {ResolveNamesResponseMessage = anyType에 {보낼 메세지 = 여러 결과가 발견되었다; ResponseCode = ErrorNameResolutionMultipleResults; DescriptiveLinkKey = 0; ResolutionSet = anyType {Resolution = anyType {Mailbox = anyType {Name = Amyj; [email protected]; RoutingType = SMTP; MailboxType = Mailbox; }; 연락처 = anyType {DisplayName = Amy John; GivenName = Amy; EmailAddresses = anyType {Entry = SIP : [email protected]; Entry = SMTP : [email protected]; }; PhysicalAddresses = anyType {Entry = anyType {CountryOrRegion = China; }; }; ContactSource = ActiveDirectory; 성 = 존; }; }; Resolution = anyType {Mailbox = anyType {Name = Amyraj; [email protected]; RoutingType = SMTP; MailboxType = Mailbox; }; 연락처 = anyType {DisplayName = Amy Raj; GivenName = Amy; EmailAddresses = anyType {Entry = SIP : [email protected]; Entry = SMTP : [email protected]; }; PhysicalAddresses = anyType {Entry = anyType {CountryOrRegion = 인도; }; }; ContactSource = ActiveDirectory; 성 = Raj; }; }; 해상도 = anyType {Mailbox = anyType {Name = shine; [email protected]; RoutingType = SMTP; MailboxType = Mailbox; }; 연락처 = anyType {DisplayName = 요셉을 비추시오. GivenName = 샤인; EmailAddresses = anyType {Entry = SIP : [email protected]; Entry = SMTP : [email protected]; }; PhysicalAddresses = anyType {Entry = anyType {CountryOrRegion = 인도; }; }; ContactSource = ActiveDirectory; 성 = 요셉; }; }; }; }; }; }

어떤 도움을 주셔서 감사합니다!

답변

-2

실제로 알고있는이 형식은 Java Script입니다. 이 형식의 데이터는 실제로는 JSON Object's and JSON Array's입니다.이 결과를 구문 분석하는 방법은 다음과 같습니다.

예 :

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

나는 이것이 당신이 당신의 문제를 해결하는 데 도움이되기를 바랍니다.

+1

참조 : http://stackoverflow.com/a/2049156/442580 – capdragon

1

나는 그것이 작동 생각이 시도

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();    
} 
관련 문제