如何解析KSOAP阵列响应 [英] How to parse ksoap array response

查看:245
本文介绍了如何解析KSOAP阵列响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WebService随便丢数据的阵列集。我使用KSOAP摆脱我的web服务,即响应。

I have a webservice that throwing a array set of data. I'm using Ksoap to get the response from my webservice ie.

{anyType的= NewDataSet {anyType的表= {anyType的= couponname券名称;
  couponimage =图像;优惠券code = code; coupondescription =描述;
  couponstartdate =开始日期; couponenddate =结束日期; ID = 1; };
  表= {anyType的= couponname票面名1; couponimage =图像;
  优惠券code = code1; coupondescription =内容描述;
  couponstartdate =启动DATE1; couponenddate =结束日期1; ID = 2; };
  表= {anyType的= couponname票面名2; couponimage =图像;
  优惠券code = code2; coupondescription =内容描述;
  couponstartdate =起始日期2; couponenddate =结束日期2; ID = 3; }; }; }

anyType{NewDataSet=anyType{Table=anyType{couponname=coupon name; couponimage=image; couponcode=code; coupondescription=description; couponstartdate=start date; couponenddate=end date; id=1; }; Table=anyType{couponname=coupon name1; couponimage=image; couponcode=code1; coupondescription=description1; couponstartdate=start date1; couponenddate=end date1; id=2; }; Table=anyType{couponname=coupon name2; couponimage=image; couponcode=code2; coupondescription=description2; couponstartdate=start date2; couponenddate=end date2; id=3; }; }; }

谁能给一个教程或建议如何解析对此有何反应?
任何想法将是非常美联社preciated。

Can anyone give a tutorial or suggestion how to parse this response? Any thoughts will be highly appreciated.

推荐答案

是的,你可以做到这一点是:

Yes you can do it as :

如果你的反应是相似的:

if your response is as similar as :

anyType{
    StatusSetting=anyType{Id=1; Name=Til afskrivning; LocationId=1; Editable=true; Default=true; Transcribed=false; }; 
    StatusSetting=anyType{Id=2; Name=Afskrevet; LocationId=1; Editable=false; Default=false; Transcribed=true; }; 
    ...
}

然后你要做的,如:

Then you have to do like :

SoapObject countryDetails = (SoapObject)envelope.getResponse();
System.out.println(countryDetails.toString());

ArrayList list = new ArrayList(countryDetails.getPropertyCount());
lv_arr = new String[countryDetails.getPropertyCount()];
for (int i = 0; i < countryDetails.getPropertyCount(); i++) {
    object property = countryDetails.getProperty(i);
    if (property instanceof SoapObject) {
        SoapObject countryObj = (SoapObject) property;
        String countryName = countryObj.getProperty("countryName").toString();
        list.add(countryName );
    }
}

如果您可以通过这个例子了解然后让我知道,否则我会送你你的反应数据的解析code。

If you can understand by this example then let me know otherwise i will send you the parsing code of data of your response.

或其他为:

您可以通过只添加得到肥皂对象XML响应:

You can get XML response from soap object by just adding the :

androidHttpTransport.debug = true;

在电话为:

androidHttpTransport.call(SOAP_ACTION, envelope);

和添加:

String xml = androidHttpTransport.responseDump;

呼叫后。

和您将获得XML列放在字符串XML。所以,你可以用任何(DOM,xmlpull或SAX)解析器解析它。

And you will get the xml out put in string xml. So you can parse it using any (DOM, xmlpull or SAX) parser.

修改1

您可以按照下面的code实现的任务是:

You can follow the following code to achieve the task :

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
       // Add the input required by web service
       request.addProperty("city","chennai");
       request.addProperty("key","10000");

       SoapSerializationEnvelope envelope =new SoapSerializationEnvelope(SoapEnvelope.VER11);
       envelope.setOutputSoapObject(request);

       // Make the soap call.
       androidHttpTransport.call(SOAP_ACTION, envelope);

       // Get the SoapResult from the envelope body.
       resultRequestSOAP = (SoapObject) envelope.bodyIn;


       System.out.println("********Response : "+resultRequestSOAP.toString());

       SoapObject root = (SoapObject) resultRequestSOAP.getProperty(0);
       SoapObject s_deals = (SoapObject) root.getProperty("FOO_DEALS");

       StringBuilder stringBuilder = new StringBuilder();

       System.out.println("********Count : "+ s_deals.getPropertyCount());

       for (int i = 0; i < s_deals.getPropertyCount(); i++) 
       {
           Object property = s_deals.getProperty(i);
           if (property instanceof SoapObject)
           {
               SoapObject category_list = (SoapObject) property;
               String CATEGORY = category_list.getProperty("CATEGORY").toString();
               String CATEGORY_URL = category_list.getProperty("CATEGORY_URL").toString();
               String CATEGORY_ICON = category_list.getProperty("CATEGORY_ICON").toString();
               String CATEGORY_COUNT = category_list.getProperty("CATEGORY_COUNT").toString();
               String SUPERTAG = category_list.getProperty("SUPERTAG").toString();
               String TYPE = category_list.getProperty("TYPE").toString();
               stringBuilder.append
               (
                    "Row value of: " +(i+1)+"\n"+
                    "Category: "+CATEGORY+"\n"+
                    "Category URL: "+CATEGORY_URL+"\n"+
                    "Category_Icon: "+CATEGORY_ICON+"\n"+
                    "Category_Count: "+CATEGORY_COUNT+"\n"+
                    "SuperTag: "+SUPERTAG+"\n"+
                    "Type: "+TYPE+"\n"+
                    "******************************"
               );                   
               stringBuilder.append("\n");
           }
       }

如果是有帮助的,你再投答案,并接受它。

If it is helpful to you then vote answer and accept it.

感谢您。

这篇关于如何解析KSOAP阵列响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆