Android KSoap2: how to get property name

I am using KSoap2 to call web services for my Android application. I am using the following code to call a web service.

SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); request.addProperty("PageSize", 20); request.addProperty("PageIndex", currentPage); SoapSerializationEnvelope soapEnvelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); soapEnvelope.dotNet = true; soapEnvelope.setOutputSoapObject(request); HttpTransportSE aht = new HttpTransportSE(URL); try { aht.call(SOAP_ACTION, soapEnvelope); SoapObject result = (SoapObject) soapEnvelope.getResponse(); Log.d("resBundle", String.valueOf(resBundle)); int elementCount = resSoap.getPropertyCount(); for(int i = 0;i<elementCount;i++){ /////////////////////how to get the property name here//////////////// } }catch (Exception e) { e.printStackTrace(); return null; } 

I get a response from web services perfectly. String.valueOf answer below:

 anyType{NewsID=2186; NewsSubject=Lil Wayne Shows Up to Heat Game With Mystery Chick & Drake; NewsDetail=Looks like Weezy found him a main chick! Lil Wayne showed off his mystery girl yet again, this time at the Miami Heat Eastern Conference Finals game. Wanye looked proud to be with his girl while he kept his arm around her for most of the game. Drake was also in attendance with Wanye and it looks like he was having a great time cheering on the Heat as they beat the Bulls in overtime. Chad Ochocinco was also spotted enjoying the game, but Evelyn was no where to be seen. Check out more pics from the Miami game:; NewsArtist=494; ModifiedDate=2011-05-26T12:03:04.567+01:00; CreateDate=26 May, 2011 12:03PM; ImageName=26052011120304.jpg; ImageAlt=anyType{}; ShortNewsDetail=Looks like Weezy found him a main chick! Lil Wayne showed off his mystery girl y; } 

Now I can easily get the value of the property, but I also want to get the name property (e.g. NewsID, NewsSubject, NewsArtist, ModifiedDate). How to get property name?

+7
source share
1 answer

If you loop your answer, you can access PropertyInfo from the difrent property. I used the following setting to get the names of the parameters and values ​​that go with them:

 //Inside your for loop PropertyInfo pi = new PropertyInfo(); resSoap.getPropertyInfo(i, pi); Log.d(TAG, pi.name + " : " + resSoap.getProperty(i).toString()); 

This creates a PropertyInfo object, adds information from the property to this object, and then gives you access to all this information. And then prints it to your LogCat in the format off "propertyname: propertyvalue"

+15
source

All Articles