2011-06-23 43 views
0

次のように私のSOAP要求とSOAP応答は次のとおりです。AndroidアプリケーションにSOAPリクエストからJSONファイルに応答を解析する方法

Test 
To test the operation using the HTTP POST protocol, click the 'Invoke' button. 
Parameter Value 
accessCode: xxxxxx 
      Invoke  


SOAP 1.1 

次は、サンプルのSOAP 1.1の要求および応答です。表示されるプレースホルダは実際の値に置き換える必要があります。

POST /UI/WebServices/CalManager.asmx HTTP/1.1 
Host: login.nediso.com 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 
SOAPAction: "http://nediso.com/add/login" 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <add_x002F_login xmlns="http://nediso.com/"> 
     <accessCode>string</accessCode> 
    </add_x002F_login> 
    </soap:Body> 
</soap:Envelope> 

HTTP/1.1 200 OK 
Content-Type: text/xml; charset=utf-8 
Content-Length: length 

<?xml version="1.0" encoding="utf-8"?> 
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> 
    <soap:Body> 
    <add_x002F_loginResponse xmlns="http://nediso.com/"> 
     <add_x002F_loginResult>string</add_x002F_loginResult> 
    </add_x002F_loginResponse> 
    </soap:Body> 
</soap:Envelope> 

ここで私は、例えば、accesscodeと上記のSOAPリクエストの形式で指定され、それは聞かせてxxxxxをSOAPリクエストを送信しています。以下では、レスポンスを文字列として取得しています。私がアクセスコードを入力してSOAPリクエストのすぐ上のInvokeボタンをクリックするときは、私は.Jsonというファイルをレスポンスとして受け取ります。ここでの問題は、レスポンスとしてStringを取得するのか、.Jsonをレスポンスとして取得するのかです。それは.Jsonファイルの場合、それを処理し、解析する方法ですか?

+0

その簡単にあなたは間違ってやっていることを伝えるためにあなたはいくつかのコードを含める必要があります。 – Femi

答えて

0

正確にはどういう意味かはっきりしませんが、リクエストからjsonレスポンスを解析するのは簡単です。 hereのgoogle-gsonライブラリを使用できます。この関数は、パラメータとして渡されたtagdata戻ります

public static String ParseJSON(String theResponse, String tag){ 
    try{ 
      String tempResp = theResponse.toUpperCase(); 
      String tempTag = tag.toUpperCase(); 
      JSONObject outer = new JSONObject(tempResp); 
      String data = (String)outer.get(tempTag); 
      return data; 
     } 
     catch(JSONException e) { 
      Log.e(LOG_TAG, e.toString()); 
     } 
} 

:あなたはあなたのライブラリをプロジェクトに追加したら、あなたのような何かを行うことができます。ですから、例えば:

String response = "Result:OK, Message:HI"; 
String msgData = ParseJSON(response, "Message"); 
System.out.println(msgData); //this will print "HI" 

ライアン

関連する問題