gpt4 book ai didi

java - android:如何在哈希表中加载sqlite数据

转载 作者:行者123 更新时间:2023-12-01 11:16:31 25 4
gpt4 key购买 nike

我是 java 和 android 新手。我想在哈希表中获取 sqlite 行,然后将它们像数据集一样发送到服务器。我以前从未使用过哈希表,因为哈希表需要两个参数键和值,我不知道如何传递键,有人可以告诉我实现此目的的正确方法是什么。

  public Hashtable<String,ChemOrderDetailTable> getDetail(){

db = DBHelper.getWritableDatabase();
Cursor c= db.query(DB_TABLE_CHEMIST_ORDERS_DETAIL, null, null, null, null, null, null, null);
Hashtable<String,ChemOrderDetailTable> hashtable =
new Hashtable<String,ChemOrderDetailTable>();
if (c != null) {
while (c.moveToNext()) {

String orderNo = c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_ORDERNO));
String prodCode = c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_PRODCODE));
String qty= c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_QTY));
String tp= c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_TYP));
String total = c.getString(c.getColumnIndex(CHEM_ORDERS_DETAIL_AMOUNT));

ChemOrderDetailTable chemDetailTable = new ChemOrderDetailTable();
chemDetailTable.setOrderNo(orderNo);
chemDetailTable.setProdCode(prodCode);
chemDetailTable.setQTY(qty);
chemDetailTable.setOrderNo(tp);
chemDetailTable.setTotal(total);

hashtable.put(key, chemDetailTable);

}
}
return hashtable;

}

最佳答案

将哈希表发送到服务器

JSONObject json = new JSONObject();
json.putAll(hashtable);

json.toString() 作为 API 中的负载发送

关于java - android:如何在哈希表中加载sqlite数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31766558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com