从android中的webservice中检索String列表

时间:2012-12-03 13:57:29

标签: android arraylist android-ksoap2

我正在尝试从我的SoapObject中检索字符串List。我正在使用KSoap2来调用我的webservice,它返回字符串List.Here是我的代码

SoapPrimitive response = (SoapPrimitive)envelope.getResponse();

任何人都可以帮我从SoapPrimitive对象中获取所有列表元素。

喜欢List abc =response.getList() or something ??

3 个答案:

答案 0 :(得分:1)

您的案例是此案例的简化版本: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)
}

答案 1 :(得分:0)

最后在@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);
}

答案 2 :(得分:0)

您可以像这样获取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;
    }
}