Android Webservices 返回多行多列数据(Dataset)
生活随笔
收集整理的這篇文章主要介紹了
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
總結
以上是生活随笔為你收集整理的Android Webservices 返回多行多列数据(Dataset)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 做自己的伯乐
- 下一篇: viewDidLoad等相关函数调用