问题描述
我使用KSoap2为我的Android应用程序调用Web服务。我使用以下code TTO调用Web服务。
I am using KSoap2 for calling web-services for my Android app. I am using following code tto call the 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;
}
我是从网络服务完美地得到响应。在将String.valueOf
的反应是如下:
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; }
现在我可以很容易地得到属性的值很容易,但我也希望得到name属性(例如NewSID的,NewsSubject,NewsArtist,ModifiedDate)。如何获得属性的名称?
Now I can easily get the value of property easily, but I also want to get the name property (e.g. NewsID, NewsSubject, NewsArtist, ModifiedDate). How to get the name of the property?
推荐答案
您循环槽你的回应,你可以从difrent属性的访问的PropertyInfo。我用下面的设置以获取参数的名称和他们一起去的值:
Where you loop trough your response you can get access to the PropertyInfo from the difrent property's. I used the following setup to get the names of the parameters and the 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());
这将创建一个PropertyInfo对象,增加了从该对象的属性信息,然后,您可以访问所有这些信息。然后将它打印在格式的LogCat中关PROPERTYNAME:为PropertyValue
This creates a PropertyInfo object, adds the information from the property in that object and then gives you access to all this information. And then prints it to your LogCat in the format off "propertyname : propertyvalue"
这篇关于Android的KSoap2如何获得属性名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!