Android KSoap2:如何获取属性名称

发布于 2024-11-17 06:20:03 字数 1880 浏览 0 评论 0原文

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

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)。如何获取房产名称?

I am using KSoap2 for calling web-services for my Android app. I am using following code to 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;
}

I am getting response from the web-services perfectly. The String.valueOf of response is 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 property easily, but I also want to get the name property (e.g. NewsID, NewsSubject, NewsArtist, ModifiedDate). How do I get the name of the property?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

故人的歌 2024-11-24 06:20:03

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

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

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

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

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"

泼猴你往哪里跑 2024-11-24 06:20:03

//在 for 循环中

SoapObject dataObject ; // 你的 SoapObject

PropertyInfo 属性 = new PropertyInfo();

dataObject.getPropertyInfo(i, 属性);

// 这应该给你属性名称

String name= property.getName();

//快乐编码

//Inside your for loop

SoapObject dataObject ; // your SoapObject

PropertyInfo property = new PropertyInfo();

dataObject.getPropertyInfo(i, property);

// this should give you the property name

String name= property.getName();

//happy coding

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文