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://blog.csdn.net/sheshou2/article/details/6298542

posted @ 2013-06-24 11:46  还是你最好  阅读(982)  评论(0编辑  收藏  举报