KSoap2 Android Receive Array of Objects
android, android-ksoap2, arrays, web-services
Solution
to get Multiple response just add few lines into your code instead of the `..........=envelope.getResponse(); `
SoapObject obj1 = (SoapObject) envelope.getResponse();
SoapObject obj2 =(SoapObject) obj1.getProperty(0);
for(int i=0; i<obj2.getPropertyCount(); i++)
{
SoapObject obj3 =(SoapObject) obj2.getProperty(i);
int id= Integer.parseInt(obj3.getProperty(0).toString());
String start_date = obj3.getProperty(1).toString();
String end_date = obj3.getProperty(2).toString();
int id= Integer.parseInt(obj3.getProperty(3).toString());
}
If you still have any Problem you can write me.
Problem
I am trying to use a .NET webservice in my application where the service returns an array of objects as a response. This is the format of the response from the web-service. ``` <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetPickersResponse xmlns="http://tempuri.org/"> <GetPickersResult> <Picker> <Id>int</Id> <StartTime>dateTime</StartTime> <EndTime>dateTime</EndTime> <PickerCount>int</PickerCount> </Picker> <Picker> <Id>int</Id> <StartTime>dateTime</StartTime> <EndTime>dateTime</EndTime> <PickerCount>int</PickerCount> </Picker> </GetPickersResult> </GetPickersResponse> </soap:Body> </soap:Envelope> ``` This is my Java code to get the response from the web-service. ``` SoapObject request = new SoapObject(NAMESPACE, METHOD_GET_CONTROL); SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); envelope.dotNet = true; envelope.setOutputSoapObject(request); HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); try { androidHttpTransport.call(SOAP_ACTION_GET_CONTROL, envelope); ..........=envelope.getResponse(); //To get the data. } ``` My question, with what do I replace the "........" in my source code to receive the array of objects as a response from the service ? I need to receive multiple objects and then use their individual data members. Please help. I am new to Web-services and Ksoap.