KSoap2 Android的接收对象的数组 [英] KSoap2 Android Receive Array of Objects
问题描述
我想在我的应用程序,其中服务返回对象的数组作为响应使用.NET Web服务。
I am trying to use a .NET webservice in my application where the service returns an array of objects as a response.
这是从web服务的响应的格式。
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>
这是我的Java code来从Web服务的响应。
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. }
我的问题,有什么我取代........在我的源$ C $ C接收对象的数组从服务的响应?
我需要接收多个对象,然后使用他们的个人数据成员。
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.
请帮忙。我是新来的Web服务和KSOAP。
Please help. I am new to Web-services and Ksoap.
推荐答案
要获得多重响应只需添加几行到您的code代替 .......... = envelope.getResponse();
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.
这篇关于KSoap2 Android的接收对象的数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!