2011-02-11 49 views
1

我尝试制作我的第一个android应用程序! 我使用kso​​ap2调用web服务来获取我的帐户的详细信息。 我有一个函数返回一个数组(resultRequestSOAP)。 在resultRequestSOAP中有一个ARRAY对象。 下面我的功能:需要帮助来显示从webservice返回的SOAP请求

public Array listall(String session){ 
    final String SOAP_ACTION = "http://www.nubio.net/soap/vps#listAll"; 
    final String METHOD_NAME = "listAll"; 
    final String NAMESPACE = "http://www.nubio.net/soap/vps"; 
    final String URL = "http://www.nubio.net/soap/vps"; 
    Array myArray = null; 
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME); 
    //SoapObject 
    request.addProperty("session",session); 
    SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11); 
    envelope.setOutputSoapObject(request); 
    HttpTransportSE androidHttpTransport = new HttpTransportSE(URL); 
    try 
     { 
      androidHttpTransport.call(SOAP_ACTION, envelope); 
      resultRequestSOAP = envelope.getResponse(); 
      //retour = resultRequestSOAP.toString(); 
      if(resultRequestSOAP != null){ 
       myArray = (Array)resultRequestSOAP; 
      } 
     } 
    catch (Exception aE) 
     { 
    aE.printStackTrace();; 
     } 
    return myArray; 

} 

我测试函数返回字符串,它工作正常,但我需要在屏幕上显示的阵列。 如何显示resultRequestSOAP中的数组; ? 但是resultRequestSOAP中soap的原始返回值;是:

array(
    0 => Object{ 
    vps_id  : int 
    ip   : string 
    hostname : string 
    password : string (optional) 
    os   : string 
    os_arch  : integer 
    os_distri : string 
    expire  : string (DATE TIME) 
    }, 
    ... 
) 

所以我可以从肥皂中返回数组并显示它!? 对不起我的英语,我希望你能帮助我:) 最适合我的只会显示数组中的“主机名字符串”,因为按钮有可能吗?

+0

什么语言和平台? – 2011-02-11 14:33:28

+0

@John:这是Java和Android平台 – 2011-02-11 17:33:08

+0

是的,它和Android平台,你能帮我吗?对不起,我的英文..你明白我想说明什么吗?感谢您的帮助 – naturlight 2011-02-11 18:00:15

回答

0

不是真的知道什么你问,但如果你的方法返回对象的数组,你可以打印出对象像这样:

for(int i=0; i < myArray.length; i++){ 
     Object item = myArray[i]; 
     // Put into a TextView here if you wish, just printing to console 
     System.out.println("Item: "+i +" IP: "+item.ip); 
     // or if it is private with a getter 
     System.out.println("Item: "+i +" IP: "+item.getIp()); 

     System.out.println("Hostname: "+item.hostname); 

     System.out.println("Hostname: "+item.getHostname()); 
} 

我想,让你的想法呢?

0

这篇博客文章可能有帮助:http://seesharpgears.blogspot.com/2010/10/web-service-that-returns-array-of.html

看到的最后一个方法。

编辑:

,而不是铸造阵列您resultRequestSOAP,你应该得到的属性与resultRequestSOAP.getPropertyCount()通过他们的数量,循环获取每个对象:从这些对象

SoapObject pii = (SoapObject)resultRequestSOAP.getProperty(i);

你可以提取自己的属性(vps_id,ip,hostname ...):

vps_id = Integer.parseInt(pii.getProperty(0).toString());

等等。在这个例子中,他们正在构建他们的Category对象的数组,但是当然你可以使用你想要的数据。