从json解析中插入数据到sqlite数据库

weixin_38083228 weixin_38083228 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

我想在android数据解析表单中的json数组数据中插入数据到sqLite数据库。 我的代码如下: 1)DBHelperClass - 数据库创建 public class DueAmountDataBHelper extends SQLiteOpenHelper { public DueAmountDataBHelper(Context context) { super(context, "abc.db", null, 1); } @Override public void onCreate(SQLiteDatabase db) { String CREATE_TABLE_PRODUCT_DUE_AMT = "create table due_amt_tab(" + "shopId text primary key, " + "shopName text NOT NULL, " + "teluguName text NOT NULL, " + "place text NOT NULL, " + "dueAmount text NOT NULL " + ")"; db.execSQL(CREATE_TABLE_PRODUCT_DUE_AMT); } @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { } public List<DueAmtDBModel> getShopdata() { List<DueAmtDBModel> data = new ArrayList<>(); SQLiteDatabase db = this.getWritableDatabase(); Cursor cursor = db.rawQuery("select * from due_amt_tab", null); StringBuffer stringBuffer = new StringBuffer(); DueAmtDBModel dataModel = null; while (cursor.moveToNext()) { dataModel = new DueAmtDBModel(); String shopId, shopName, teluguName, place, dueAmount; shopId = cursor.getString(cursor.getColumnIndexOrThrow("shopId")); shopName = cursor.getString(cursor.getColumnIndexOrThrow("shopName")); teluguName = cursor.getString(cursor.getColumnIndexOrThrow("teluguName")); place = cursor.getString(cursor.getColumnIndexOrThrow("place")); dueAmount = cursor.getString(cursor.getColumnIndexOrThrow("dueAmount")); dataModel.setShopId(shopId); dataModel.setShopName(shopName); dataModel.setTeluguName(teluguName); dataModel.setPlace(place); dataModel.setDueAmount(dueAmount); stringBuffer.append(dataModel); data.add(dataModel); } return data; } } 这个表我需要插入此JSON数据 APi的 - http://demo4896782.mockable.io/shops [ { "shopName": "Hello World.", "shopTeluguName": "శరవాన గుడ్డు పంపిణీదారులు", "shopAddress": "Bomanahalli", "previousDues": 0, "shopID": 1 }, { "shopName": "Hello World.", "shopTeluguName": "శరవాన గుడ్డు పంపిణీదారులు", "shopAddress": "Bomanahalli", "previousDues": 20, "shopID": 2 }, { "shopName": "Hello World.", "shopTeluguName": "శరవాన గుడ్డు పంపిణీదారులు", "shopAddress": "Bomanahalli", "previousDues": 400, "shopID": 3 } ] 预先感谢您。








...全文

相关推荐

评论 2
收藏 已收藏
分享
返回顶部