2012-03-29 10 views
1

私はKSoap2 in androidを使ってWebサービスを呼び出しましたが、私が得た応答は次のとおりです。このksoapをAndroidで解析する方法Android:KSOAP2レスポンスを解析する方法

ResolveNamesResponse {ResponseMessages = anyTypeを{ResolveNamesResponseMessage = anyTypeを{MessageText =複数 結果が見出されました; ResponseCode = ErrorNameResolutionMultipleResults; DescriptiveLinkKey = 0; ResolutionSet = anyType {解像度= anyType {メールボックス= anyType {名前= Amyj; [email protected]; RoutingType = SMTP; MailboxType =メールボックス。 };連絡先= anyType {DisplayName = Amy John; GivenName = Amy; EmailAddresses = anyType {Entry = SIP:[email protected]; Entry = SMTP:[email protected]; }; PhysicalAddresses = anyType {Entry = anyType {CountryOrRegion = China; }; }; ContactSource = ActiveDirectory;姓=ジョン; }; }; 解決= anyType {メールボックス= anyType {名前= Amyraj; [email protected]; RoutingType = SMTP; MailboxType =メールボックス。 };連絡先= anyType {DisplayName = Amy Raj; GivenName = Amy; EmailAddresses = anyType {Entry = SIP:[email protected]; Entry = SMTP:[email protected]; }; PhysicalAddresses = anyType {Entry = anyType {CountryOrRegion = India; }; }; ContactSource = ActiveDirectory;姓= Raj; }; }; 解決= anyType {メールボックス= anyType {名前=輝き; EmailAddress = [email protected]; RoutingType = SMTP; MailboxType =メールボックス。 };連絡先= anyType {DisplayName = Shine Joseph; GivenName = Shine; EmailAddresses = anyType {Entry = SIP:[email protected]; Entry = SMTP:[email protected]; }; PhysicalAddresses = anyType {Entry = anyType {CountryOrRegion = India; }; }; 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

REFERENCE: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();    
} 
関連する問題