1

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

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

我正在使用 ksoap2 在我的 android 应用程序中获取 web 服务数据。

我已经尝试使用chadi cortbaoui's solution from this 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);

我尝试过使用 theSoapPrimitive而不是SoapObject我也尝试过使用envelope.getResponse()in 代替,envelope.bodyIn但它不起作用,它会引发相同的错误。

4

1 回答 1

0

我在这个问题的帮助下使用以下代码解决了我的问题

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*/
}

谢谢。

于 2013-09-25T12:52:40.190 回答