请告诉我如何在ksoap2 Result中检索多个数据数组。 实际上让我解释一下。 我有一个员工搜索的网络服务。当我按名称搜索时,它给了我多个记录。一条记录包含姓名,姓氏,电话,地址等,共有30,40条记录。
在我们刚收到一个输出结果的其他情况下,我们可以在ksoap2中使用以下代码
SoapObject result=(SoapObject)envelope.getResponse(); //get response
String text = result.getProperty("response").toString();
这将返回Response属性中的字符串,但仅返回一条记录。现在我们有多个记录我们如何存储每条记录。或者应该如何操纵所有记录。
请朋友指导我。 :)
让我添加更多细节..这是我得到的xml。
<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>
答案 0 :(得分:3)
这是一个解析对象数组的示例代码:
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);
}
}
取自here
答案 1 :(得分:0)
答案 2 :(得分:0)
试试这段代码:
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);
}
}
这适合我。