get data from ksoap2 in android

独自空忆成欢 提交于 2020-01-12 11:04:32

问题


please tell me how to retrieve multiple array of data in ksoap2 Result. actually let me explain. i have a web service of employee search. when i search by name it gives me Multiple Records. one record contain name, last name, phone, address etc and there are total 30,40 records.

in other cases where we just recieve one output result we can use the following code in ksoap2

SoapObject result=(SoapObject)envelope.getResponse(); //get response
String text = result.getProperty("response").toString();

This will return us the string from Response property but for only one record. now we have mutiple records how do we store each record. or how should be manipulate all the records.

Please friends guide me. :)

let me add some more details.. this is the xml i get as a result.

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
<SOAP-ENV:Body>
  <ns1:searchResponse xmlns:ns1="urn:abcdwsdl">
     <return xsi:type="SOAP-ENC:Array" SOAP-ENC:arrayType=":[6]">
        <item xsi:type="xsd:string">success</item>
        <item xsi:type="xsd:string">Search results retrieved for *</item>
        <item xsi:type="xsd:">
           <item>
              <ad_id xsi:type="xsd:string">2</ad_id>
              <fname xsi:type="xsd:string">abcr</ad_text>
              <lname xsi:type="xsd:string">def</location>
              <phone xsi:type="xsd:float">123456</lati>
              <address xsi:type="xsd:float">America</longi>
           </item>
           <item>
              <ad_id xsi:type="xsd:string">12</ad_id>
              <fnamet xsi:type="xsd:string">test user</ad_text>
              <lname xsi:type="xsd:string">hello</location>
              <phone xsi:type="xsd:float">987654543</lati>
              <address xsi:type="xsd:float">England</longi>
           </item>
        </item>
        <item xsi:type="xsd:int">2</item>
        <item xsi:type="xsd:int">0</item>
        <item xsi:type="xsd:int">0</item>
     </return>
  </ns1:searchResponse>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

回答1:


Here's a sample code that parses an array of objects:

ArrayList<Pojo> pojos = null;
int totalCount = soapobject.getPropertyCount();
if (detailsTotal > 0 ) {
    pojos = new ArrayList<Pojo>();
    for (int detailCount = 0; detailCount < totalCount; detailCount++) {
        SoapObject pojoSoap = (SoapObject) soapobject.getProperty(detailCount);
        Pojo Pojo = new Pojo();
        Pojo.idNumber = pojoSoap.getProperty("idNumber").toString();
        Pojo.quantity =  pojoSoap.getProperty("quantity").toString();

        pojos.add(Pojo);
    }
}

Taken from here




回答2:


This is The Answer:

ksoap2 in android in Multiple Array Data Retrieving




回答3:


Try this code:

List<MyObject> list = new ArrayList<MyObject>();
if (soapObject != null && soapObject.getPropertyCount() > 0) {
   for (int i = 0; i < soapObject.getPropertyCount(); i++) {
      SoapObject so = (SoapObject) soapObject.getProperty(i);
      MyObject obj = new MyObject();
      obj.setProperty1(so.getPropertyAsString("property1"));
      obj.setProperty2(so.getPropertyAsString("property2"));
      list.add(obj);
   }
}

That works for me.



来源:https://stackoverflow.com/questions/5974801/get-data-from-ksoap2-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!