سؤال

I have an array of object coming from a PHP web service which has contents like :

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

I am using ksoap2 to get the webservice data in my android application.

I have tried by using the chadi cortbaoui's solution from this question but it is giving error

java.lang.ClassCastException: java.util.Vector cannot be cast to org.ksoap2.serialization.SoapObject

for line SoapObject response1 = (SoapObject) response.getProperty(0); with following code

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

I have tried by using the SoapPrimitive instead of SoapObject also i have tried by using the envelope.getResponse() in place of envelope.bodyIn but it does not work it throws the same error.

هل كانت مفيدة؟

المحلول

I solved my problem by using the following code with the help of this 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*/
}

thanks.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top