zoukankan      html  css  js  c++  java
  • Android Webservices 返回多行多列数据(Dataset)

    对于之前从事.net或者java开发人员,习惯了从后台获取网格数据(多行多列DataTable),但转行从事android开发,难免会不习惯

    Android调用Webservice时,如果返回值是一个boolean或者string值时可以通过下面方式接收返回值:

    SoapObject soapObject = (SoapObject) envelope.getResponse();  
    Re = soapObject.getProperty("twgp") 

    如果接收是一行值时也可以通过上面的方式去获取,但是如果返回的是多行多列或者一行多列的数据集时就比较麻烦了,上面的方法不管用,不然的话接收到的值永远是第一行的值,所以对于那种多行多列的返回值时,如下面的webservice:

    //运价查询  
    @SuppressWarnings("unchecked")  
    @Repository("priceDao")  
    public class PriceDao extends BaseOraDao {  
      
        public List getPrice(String fromPort, String toPort){  
            List foo;  
            StringBuffer sb = new StringBuffer();  
            sb.append("select max(price20gp) as price20GP,max(price40gp) as price40gp,max(price40h) ");  
            sb.append("as price40h from ");  
            sb.append("(select * from nqprice_main n where n.feetype='水运费' and n.fromport='");  
            sb.append(fromPort).append("' ");  
            sb.append("and n.toport='").append(toPort).append("' ");  
            sb.append("and n.endday is null order by n.beginday desc) where rownum<=2");  
              
            foo = getNqoraJdbcTemplate().query(sb.toString(), new RowMapper() {  
                public Object mapRow(ResultSet rs, int rowNum) throws SQLException {  
                      Price dm = new Price();  
                      dm.setTwgp(String.valueOf(rs.getDouble("price20GP")));  
                      dm.setFtgp(String.valueOf(rs.getDouble("price40gp")));  
                      dm.setFtgp(String.valueOf(rs.getDouble("price40h")));  
                      return dm;  
                }             
            });  
              
            return foo;  
        }  
    }   }  
    }  

    经过一天研究发现有一种办法获取:

    //构造数据  
    ArrayList<String> list = null;  
    //web service请求  
    ht.call(null, envelope);  
    //得到返回结果  
    result = (SoapObject) envelope.bodyIn;  
    for (int i = 0; i < result.getPropertyCount(); i++) {  
        SoapObject soapChilds =(SoapObject)result.getProperty(i);  
      
        list.add(soapChilds.getProperty("price20GP").toString());  
    }  
    //这样list就包含了返回列price20GP的数据  

    结合下面文章怎样去调用webservices

    http://blog.csdn.net/sheshou2/article/details/6138865

    出处:http://www.verydemo.com/demo_c131_i65117.html

  • 相关阅读:
    node实现图片分割
    Windows10开启Ubuntu子系统并搭建Docker环境
    从零搭建Window前端开发环境
    apue 文章集锦
    [apue] Linux / Windows 系统上只能建立不超过 PATH_MAX / MAX_PATH 长度的路径吗?
    [apue] 一个快速确定新系统上各类限制值的工具
    [apue] sysconf 的四种返回状态
    [apue] epoll 的一些不为人所注意的特性
    一个工业级、跨平台、轻量级的 tcp 网络服务框架:gevent
    [apue] 书中关于打印服务代码的一个错误
  • 原文地址:https://www.cnblogs.com/gzggyy/p/3064958.html
Copyright © 2011-2022 走看看