需要帮助显示 Web 服务的 SOAP 请求的返回

发布于 2024-10-17 03:33:26 字数 1682 浏览 1 评论 0原文

我尝试制作我的第一个 Android 应用程序! 我使用 ksoap2 调用 Web 服务来获取我的帐户的详细信息。 我有一个返回数组的函数(resultRequestSOAP)。 在 resultRequestSOAP 中有一个对象数组。 在我的函数下面:

    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)
   },
   ...
)

所以我可以从肥皂返回数组并显示它!? 我很抱歉我的英语,我希望你能帮助我:) 对我来说最好的将仅显示数组中的“主机名字符串”作为按钮,这可能吗?

I try to make my first android app !
I call a webservice with ksoap2 to get details of my account.
I have a function witch return a Array (resultRequestSOAP).
In the resultRequestSOAP there is an ARRAY of object.
Below my function :

    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;

}

I test the function to return string and it's works fine, but i need to show the array on the screen.
How can i display the array in the resultRequestSOAP; ?
But the original return of the soap in resultRequestSOAP; is :

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)
   },
   ...
)

So i can i return the array from the soap and display it!?
I'm sorry for my english, i hope you could help me :)
The best for me will only display the "hostname string" from the array as button is it possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

凉风有信 2024-10-24 03:33:26

不太确定你的要求是什么,但如果你的方法返回一个对象数组,你可以像这样打印该对象:

 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());
 }

我认为这给了你这个想法?

Not really sure what your asking, but if you method returns an array of objects you can print that object out like this:

 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());
 }

I think that gives you the idea anyway?

南巷近海 2024-10-24 03:33:26

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

查看最后一个方法。

编辑:

您应该使用 resultRequestSOAP.getPropertyCount() 获取属性的数量,而不是转换为 resultRequestSOAP 数组,并循环遍历它们以获取每个对象:

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

从这些对象中,您可以使用以下方法提取它们自己的属性(vps_id、ip、主机名...):

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

等等。在示例中,他们正在构建其 Category 对象的数组,但当然您可以根据需要使用数据。

this blog post might help: http://seesharpgears.blogspot.com/2010/10/web-service-that-returns-array-of.html

see the last method.

edit:

instead of casting to array your resultRequestSOAP, you should get the number of properties with resultRequestSOAP.getPropertyCount(), and cycle through them to get each object:

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

from these objects you can extract their own properties (vps_id, ip, hostname...) with:

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

and so on. in the example they're building an array of their Category objects, but of course you can use the data like you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文