get data from ksoap2 in android

瘦欲@ 提交于 2019-12-03 21:38:30

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

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.

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