我正在尝试从我的 SoapObject 中检索字符串列表。我正在使用 KSoap2 调用我的 Web 服务,它返回字符串列表。这是我的代码
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
谁能帮我从我的 SoapPrimitive 对象中获取所有列表元素。
喜欢List abc =response.getList() or something
??
我正在尝试从我的 SoapObject 中检索字符串列表。我正在使用 KSoap2 调用我的 Web 服务,它返回字符串列表。这是我的代码
SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
谁能帮我从我的 SoapPrimitive 对象中获取所有列表元素。
喜欢List abc =response.getList() or something
??
您的案例是此案例的简化版本:Parsing kSoap response to array of objects
但略有不同的是,您的对象很简单:
SoapObject result = (SoapObject) envelope.getResponse();
SoapObject soapresults = (SoapObject)result.getProperty(0);
int count = soapresults.getPropertyCount();
ArrayList<PT> simplifiedList = new ArrayList<PT>();
for (int i = 0; i < count; i++)
{
soapresults.getPropertyAs(PT)(i)
}
终于在@Thunder 的建议的帮助下得到了答案,而不是
SoapObject result = (SoapObject) envelope.getResponse(); 我们必须使用
java.util.Vector<String> result11 = (java.util.Vector<String>)envelope.getResponse(); // to get List of Strings from the SoapObject.. then
ArrayList<String> prjList = new ArrayList<String>();
for(String cs : result11)
{
prjList.add(cs);
}
你可以像这样得到你的soapObject的字符串:
SoapObject resSoap =(SoapObject)envelope.bodyIn;
int count = resSoap.getPropertyCount();
for (int i=0; i<count;i++){
SoapObject so = (SoapObject) resSoap.getProperty(i);
int idxic = so.getPropertyCount();
lst= new String[idxic];
String item;
for (int e=0; e<idxic;e++){
item=so.getProperty(e).toString();
lst[e]=item;
}
}