-1

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

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

jimpanzer
  • 3,470
  • 4
  • 44
  • 84
test test
  • 284
  • 1
  • 6
  • 18

1 Answers1

2

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

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

OR other as:

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

androidHttpTransport.debug = true;

before the call as:

androidHttpTransport.call(SOAP_ACTION, envelope);

and add:

String xml = androidHttpTransport.responseDump;

after the call.

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

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");
    }
}
Pang
  • 9,564
  • 146
  • 81
  • 122
Manoj Fegde
  • 4,786
  • 15
  • 50
  • 95
  • w0w thanks for your answer. Can you really send me the code how to parse my response? – test test Apr 26 '13 at 07:57
  • Yes if you need. But the better way is just take the xml of out put and use sax parsing on that. But if you need i will give you the code. And vote up my answer if you got help from it. – Manoj Fegde Apr 26 '13 at 08:19
  • ok i will vote up you answer and accept it as well can you pls send it to my email? – test test Apr 26 '13 at 08:25
  • OK but need some time as i am busy a bit now. – Manoj Fegde Apr 26 '13 at 08:28
  • ok just comment me up here if you already finished it. thanks – test test Apr 26 '13 at 08:29
  • what is countryName here.I'm also getting same result as follows:anyType{schema=anyType{element=anyType{complexType=anyType{choice=anyType{element=anyType{ complexType=anyType{sequence=anyType{element=anyType{}; element=anyType{}; element=anyType{}; }; }; }; }; }; }; }; diffgram=anyType{NewDataSet=anyType{Table=anyType{ClientType=H; ClientCode=931; ClientName=Navin Jumani; }; }; }; } – Vishwanath Deshmukh Aug 22 '13 at 06:19
  • Can you please help me too to get ClientName? – Vishwanath Deshmukh Aug 22 '13 at 06:20