从android中的ksoap2获取数据

发布于 2024-11-06 07:25:45 字数 2125 浏览 2 评论 0原文

请告诉我如何检索 ksoap2 结果中的多个数据数组。 实际上让我解释一下。 我有一个员工搜索网络服务。当我按名称搜索时,它会给我多个记录。一条记录包含姓名、电话、地址等,总共 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尴尬癌患者 2024-11-13 07:25:46

以下是解析对象数组的示例代码:

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'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

橘寄 2024-11-13 07:25:46

试试这个代码:

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);
   }
}

这对我有用。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文