Android Webservices 返回多行多列資料(Dataset)

來源:互聯網
上載者:User

對於之前從事.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

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.