返回从soap到android的字符串数组

时间:2013-11-23 16:29:43

标签: java android arrays web-services ksoap2

我正在使用Soap web服务for android,它应该返回字符串数组,但我在检索数组或数组元素时遇到一些问题

但我有一些其他的整数数组,工作正常!

    try {
    SoapObject request5 = new SoapObject(NAMESPACE5, METHOD_NAME5);
    HttpTransportSE androidHttpTransport5 = new HttpTransportSE(URL5);
    PropertyInfo pi = new PropertyInfo();
    pi.setName("TID");
    pi.setValue(TID);
    pi.setType(Integer.class);
    request5.addProperty(pi);
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
            SoapEnvelope.VER11);
    envelope.setOutputSoapObject(request5);


        androidHttpTransport5.call(SOAP_ACTION5, envelope);

        // HERE IS THE PROBLEM 
        Object  result=  envelope.getResponse();  



        String str = null;
        for (int i = 0; i < (result).getPropertyCount(); i++) {
            str = ((String) ( result).getProperty(i).toString());

            StudentIdList.add(get(str));

        }

        p.setids(StudentIdList);

    } catch (SocketTimeoutException e) {
        p.seterror("error");
        return p;

    }

    catch (ConnectTimeoutException e) {
        p.seterror("error");
        return p;

    } catch (Exception e) {

        p.seterror(e.toString());
        return p;
    }   

日志:

  The method getProperty(int) is undefined for the type Object

1 个答案:

答案 0 :(得分:0)

改变这个:

Object  result=  envelope.getResponse();  

对此:

SoapObject result = (SoapObject)envelope.getResponse();

详细信息: (result).getPropertyCount()(result).getProperty(i)无法执行。它们会导致编译错误,因为您当前的result定义是Object,并且getPropertyCount类型没有getPropertyObject等方法。因此,您必须将回复转发给SoapObject