我正在嘗試從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());
}
}
}
感謝您的意見。我找到了一個提供了另一種做事方式的頁面。現在,我得到了它的工作。非常感謝您的幫助。 – 2010-05-17 01:26:17