我想从android中的java webservice检索值数组。我正在使用带依赖关系的ksoap 3.0 jar。
我想检索值数组,如下所示:
数组([resultStatus] => true [responseObjSize] => 12 [responseObjects] =>数组([0] =>数组([item] =>数组([0] => 1 [1] => 1))[1] =>数组([item] =>数组([0] => 2 [1] => 0))[2] =>数组([] item] =>数组([0] => 3 [1] => 0))[3] =>数组([item] =>数组([0] => 4 [1] = > 0))[4] =>数组([item] =>数组([0] => 5 [1] => 0))[5] =>数组([item] => ;数组([0] => 6 [1] => 0))[6] =>数组([item] =>数组([0] => 7 [1] => 0) )[7] =>数组([item] =>数组([0] => 8 [1] => 0))[8] =>数组([item] =>数组([] 0] => 9 [1] => 0))[9] =>数组([item] =>数组([0] => 10 [1] => 0))[10] =>数组([item] =>数组([0] => 11 [1] => 0))[11] =>数组([item] =>数组([0] => ; 12 [1] => 0))))
任何人都可以帮助我。
答案 0 :(得分:0)
public static final String NAMESPACE =“http://tempuri.org/”;
public static String GetColor(Context c) throws IOException,
XmlPullParserException {
String METHOD_NAME = "GetColor";
String SOAP_ACTION = "http://tempuri.org/youruri name/";
SOAP_ACTION = SOAP_ACTION + METHOD_NAME;
SoapObject request = new SoapObject(NAMESPACE,
METHOD_NAME);
// Use this to add parameters
// Declare the version of the SOAP request
return WebCalls.call(c, request, .NAMESPACE, METHOD_NAME,
SOAP_ACTION);
}
public static String call(Context c, SoapObject request, String NAMESPACE,
String METHOD_NAME, String SOAP_ACTION) throws IOException,
XmlPullParserException {
Log.i(WebCalls, "URL " + your URL);
Log.i(WebCalls, "Method Name " + METHOD_NAME);
Log.i(WebCalls, "request Name " + request);
String SoapResult = null;
SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
SoapEnvelope.VER11);
envelope.setOutputSoapObject(request);
envelope.dotNet = true;
HttpTransportSE androidHttpTransport = new HttpTransportSE(
CommonVariable.URL);
// this is the actual part that will call the webservice
androidHttpTransport.call(SOAP_ACTION, envelope);
// Get the SoapResult from the envelope body.
if (envelope.bodyIn instanceof SoapFault) {
SoapResult = ((SoapFault) envelope.bodyIn).faultstring;
} else {
SoapObject resultsRequestSOAP = (SoapObject) envelope.bodyIn;
SoapResult = resultsRequestSOAP.getProperty(0).toString();
}
Log.i(WebCalls, "Response " + SoapResult);
return SoapResult;
}
我希望这也是有用的方法你...如果有任何查询然后告诉我..这个代码已经在我当前的项目中实现。现在它工作正常。
答案 1 :(得分:0)
dipali的代码可以帮助您使用webService。 一旦你有了SoapResult,你必须解组它才能获取所有的响应元素。
如果你的Soap响应只是一个整数数组,这里有一个例子:
SoapObject obj =(SoapObject) resultsRequestSOAP.getProperty(0);
for(int i=0; i<obj.getPropertyCount(); i++)
{
int id= Integer.parseInt(obj.getProperty(i).toString());
//Do what you want
}