从解析响应KSOAP属性名称和值 [英] Parsing property name and value from ksoap response
问题描述
所以,我有我的WebService连接到我的Android应用程序没有任何问题,并能得到答复,没有任何问题,但我想知道是否有任何方式获得SoapObject的属性名以及价值,而不是刚开的价值?
例如我得到这个反应(这只是一个样本一个非常简单的回应)
{anyType的= AsOfDate 2014-02-12T12:58:27-08:00; StatusID = 9; }
现在解析我希望能够从我的反应采取的值,然后创建一个列表(如放入NSDictionary),所以我可以当一个键/值对这样的:
AsOfDate = 2014-02-12T12:58:27-08:00;
StatusID = 9;
但到目前为止,我还没有能够缩小我如何能得到解析时,属性名,这是我到目前为止有:
SoapObject errortable =(SoapObject)dataset.getProperty(ErrorTable);
的for(int i = 0; I< errortable.getPropertyCount();我++){
Object对象= errortable.getProperty(I)
//Log.d(ENSI_DEBUG的目的是:+ object.getClass());
如果(对象的instanceof SoapObject){
Log.d(ENSI_DEBUG的对象是一个肥皂对象=+对象);
}
如果(对象的instanceof SoapPrimitive){
Log.d(ENSI_DEBUG的对象包含值:+ object.toString()+和名称://这里的地方我想获得的属性名称创建键/值对);
}
}
我想通了这个问题,我需要使用物业信息对象来获取的名字,所以最后我用下面这个code得到什么我需要。
SoapObject结果=(SoapObject)response.getProperty(结果);
SoapObject的DiffGram =(SoapObject)result.getProperty(DiffGram格式);
SoapObject数据=(SoapObject)diffgram.getProperty(NewDataSet);
对于(INT J = 0; J< dataset.getPropertyCount(); J ++){
SoapObject finalObject =(SoapObject)dataset.getProperty(J);
的for(int i = 0; I< finalObject.getPropertyCount();我++){
Object对象= finalObject.getProperty(I)
的PropertyInfo的PropertyInfo =新的PropertyInfo();
finalObject.getPropertyInfo(I,的PropertyInfo);
如果(对象的instanceof SoapPrimitive){
hashMap.put(propertyInfo.name,object.toString());
}
}
dataList.add(HashMap的);
}
So I've got my WebService connected to my Android app without any problems, and can get responses without any problems but I wanted to know if there's any way to get the Property name of the SoapObject as well as the value, instead of just getting the value?
For example I get this response (this is a very simple response just for a sample)
anyType{AsOfDate=2014-02-12T12:58:27-08:00; StatusID=9; }
Now when parsing I wanted to be able to take the values from my response and then create a List (like a NSDictionary) so I can have a key/value pair like :
AsOfDate = 2014-02-12T12:58:27-08:00;
StatusID = 9;
But so far I haven't been able to narrow down how I can get the property name when parsing, here's what I have so far:
SoapObject errortable = (SoapObject)dataset.getProperty("ErrorTable");
for (int i = 0; i < errortable.getPropertyCount(); i++) {
Object object = errortable.getProperty(i);
//Log.d(ENSI_DEBUG, "the object is: " + object.getClass());
if (object instanceof SoapObject) {
Log.d(ENSI_DEBUG, "the object is a soap object = " + object);
}
if (object instanceof SoapPrimitive) {
Log.d(ENSI_DEBUG, "the object contains value: " + object.toString() + " and name: " //here's where I would like to get the property name to create the key/value pair );
}
}
I figured out the problem, I needed to use the Property Info object to get the name, so I ended up using this code below to get what I needed.
SoapObject result = (SoapObject) response.getProperty("result");
SoapObject diffgram = (SoapObject) result.getProperty("diffgram");
SoapObject dataset = (SoapObject) diffgram.getProperty("NewDataSet");
for (int j = 0; j < dataset.getPropertyCount(); j++) {
SoapObject finalObject = (SoapObject) dataset.getProperty(j);
for (int i = 0; i < finalObject.getPropertyCount(); i++) {
Object object = finalObject.getProperty(i);
PropertyInfo propertyInfo = new PropertyInfo();
finalObject.getPropertyInfo(i, propertyInfo);
if (object instanceof SoapPrimitive) {
hashMap.put(propertyInfo.name, object.toString());
}
}
dataList.add(hashMap);
}
这篇关于从解析响应KSOAP属性名称和值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!