从android中的webservice获取数组列表

时间:2013-09-25 09:17:27

标签: php android web-services android-ksoap2

我有一个来自PHP Web服务的对象数组,其内容包括:

anyType[
objectname1{element1=1234567890; element2=test; element3=1110; element3=72.824043; },
objectname1{element1=11090999; element2=test; element3=2292; element3=72.824043; }]

我正在使用kso​​ap2来获取我的Android应用程序中的web服务数据。

我尝试使用此chadi cortbaoui's中的question解决方案,但是它给出了错误

  

java.lang.ClassCastException:java.util.Vector无法强制转换为   org.ksoap2.serialization.SoapObject

代码行SoapObject response1 = (SoapObject) response.getProperty(0);,代码为

envelope.encodingStyle = "UTF-8";
httpTransport.debug = true;
httpTransport.call(SOAP_ACTION, envelope);
response =  (SoapObject) envelope.bodyIn;
SoapObject response1 = (SoapObject) response.getProperty(0);

我尝试使用SoapPrimitive代替SoapObject我也试过使用envelope.getResponse()代替envelope.bodyIn,但它不起作用它会抛出相同的错误。

1 个答案:

答案 0 :(得分:0)

我在question

的帮助下使用以下代码解决了我的问题
httpTransport.call(SOAP_ACTION, envelope);
response =  (SoapObject) envelope.bodyIn;
Vector<?> responseVector = (Vector<?>) response.getProperty(0);//store the response object values in a Vector(It solved the vector error which i was getting

int count=responseVector.size();

for (int i = 0; i <count; ++i) { //for loop for the array of the result    
SoapObject test=(SoapObject)responseVector.get(i);
String value1 = test.getProperty("value1").toString();//get Your values from the soap object
String value2 = test.getProperty("value2").toString();
String value3 = test.getProperty("value3").toString();
String value4 = test.getProperty("value4").toString();
  /*thats it now add the received values to your list using the for loop*/
}

感谢。