2013-11-23 76 views
0

我使用SOAP網絡服務的Android和它應該返回字符串數組,但我在檢索數組或數組元素肥皂字符串返回數組到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 

回答

0

更改此:

Object result= envelope.getResponse(); 

要這樣:

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

詳細信息:(result).getPropertyCount()(result).getProperty(i)無法執行。他們將導致編譯錯誤,因爲您當前的result定義爲Object,並且Object類型沒有類似getPropertyCountgetProperty的方法。所以你必須投你的迴應SoapObject