草庐IT

Android KSoap2 : how to get property name

coder 2023-11-29 原文

我正在使用 KSoap2 为我的 Android 应用程序调用网络服务。我正在使用以下代码来调用网络服务。

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

现在,我可以轻松地轻松获取属性的值,但我还想获取名称属性(例如 NewsID、NewsSubject、NewsArtist、ModifiedDate)。如何获取属性的名称?

最佳答案

在循环遍历响应的地方,您可以访问不同属性的 PropertyInfo。我使用以下设置来获取参数的名称和它们附带的值:

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

这将创建一个 PropertyInfo 对象,将来自属性的信息添加到该对象中,然后您可以访问所有这些信息。然后以 off "propertyname : propertyvalue"的格式将其打印到您的 LogCat

关于Android KSoap2 : how to get property name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6493762/

有关Android KSoap2 : how to get property name的更多相关文章

随机推荐