2010-05-16 52 views
0

我正在嘗試從Web服務調用中檢索信息。以下是我目前爲止的內容。在我的文本視圖,它顯示從Web服務調用中檢索信息

Map {item=anyType{key=TestKey; value=2;}; item=anyType{key=TestField; value=adsfasd; };} 

當我跑在調試器,我可以在可變看到上面的信息,TempVar的。但問題是,我如何檢索信息(即每個陣列位置的「關鍵」和「值」的實際值)?是的,我知道onCreate有很多事情要做,我會稍後再解決。

由於提前, 蒙

我的代碼如下,

import java.util.Vector; 

import android.app.Activity; 
import android.os.Bundle; 
import android.widget.TextView; 

import org.ksoap2.SoapEnvelope; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.AndroidHttpTransport; 


public class ViewHitUpActivity extends Activity { 
private static final String SOAP_ACTION = "test_function"; 
private static final String METHOD_NAME = "test_function"; 
private static final String NAMESPACE = "http://www.monteandjanicechan.com/"; 
private static final String URL = "http://www.monteandjanicechan.com/ws/test_ws.cfc?wsdl"; 
// private Object resultRequestSOAP = null; 
private TextView tv; 

/** Called when the activity is first created. */ 
@Override 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
tv = (TextView)findViewById(R.id.people_view); 

//SoapObject 
request.addProperty("test_item", "1"); 
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
envelope.setOutputSoapObject(request); 


AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(URL); 
try 
{ 
androidHttpTransport.call(SOAP_ACTION, envelope); 
/* 
resultRequestSOAP = envelope.getResponse(); 
Vector tempResult = (Vector) resultRequestSOAP("test_functionReturn"); 
*/ 
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn; 

Vector tempResult = (Vector) resultsRequestSOAP.getProperty("test_functionReturn"); 

int testsize = tempResult.size(); 

// SoapObject test = (SoapObject) tempResult.get(0); 

//String[] results = (String[]) resultRequestSOAP; 

Object tempvar = tempResult.elementAt(1); 

tv.setText(tempvar.toString()); 
} 
catch (Exception aE) 
{ 
aE.printStackTrace(); 
tv.setText(aE.getClass().getName() + ": " + aE.getMessage()); 
} 
} 
} 

回答

0

我實際上找到了一種替代方法來做到這一點。我使用cfproperty重新構建了我的Web服務,以定義Web服務中的屬性。然後在web服務中,我使用以下方法獲取屬性:

SoapObject test =(SoapObject)tempResult.get(0);

 String temp_string = (String) test.getProperty("TestKey"); 
     temp_string = temp_string + " " + (String) test.getProperty("TestField"); 

現在,一切工作都應該如此。

0

你應該看看Ksoap2的文件,以便充分了解正在發生的事情。但是,我猜測你的Object tempvar可以變成java.util.Map,它有讀取密鑰和提取每個密鑰的值的方法。

+0

感謝您的意見。我找到了一個提供了另一種做事方式的頁面。現在,我得到了它的工作。非常感謝您的幫助。 – 2010-05-17 01:26:17