我从 API 获取数据,然后将该数据插入 SQLite 数据库。但是当我插入该数据时,出现了一些问题。我无法找出那个问题。我正在从 API 获取正确的数据。没有问题。唯一的问题是将数据插入数据库。
我的 Json 数据格式是:
{"sku":"T_010","product_id":"7","name":"footaball","thumbnail_image":" http://www.keyss.in/pos/magento/media/catalog/product/ no_selection ","description":null,"short_description":null,"weight":"0.0000","created_at":"2013-01-15 07:00:36","updated_at":"2013-01-15 07:00:36","price":"13.0000","special_price":null,"tax_class_id":"1","cat_id":["4","15"],"cat_name":{"4 ":"手机和配件","15":"运动健身"}},
我的主要课程
我的 ProductDbHandler 类 链接到我的数据库类
Getter 和 Setter 类链接到 Getter 和 Setter 类
My Logcat 显示如下:
02-05 12:31:39.601: I/Database(274): sqlite returned: error code = 1, msg = table tbProductDetails has no column named cat_id
02-05 12:31:39.621: E/Database(274): Error inserting cat_id=["5"] price=10.0 updated_at=null weight=1.0 product_id=1 tax_class_id=0 description=324354 thumbnail_image=http://www.keyss.in/pos/magento/media/catalog/product/no_selection name=assdfg created_at=2013-01-15 06:19:59 sku=T_001 special_price=12.0 cat_name={"5":"Cameras"}
02-05 12:31:39.621: E/Database(274): android.database.sqlite.SQLiteException: table tbProductDetails has no column named cat_id: , while compiling: INSERT INTO tbProductDetails(cat_id, price, updated_at, weight, product_id, tax_class_id, description, thumbnail_image, name, created_at, sku, special_price, cat_name) VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteCompiledSql.native_compile(Native Method)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteCompiledSql.compile(SQLiteCompiledSql.java:91)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteCompiledSql.<init>(SQLiteCompiledSql.java:64)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteProgram.<init>(SQLiteProgram.java:80)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteStatement.<init>(SQLiteStatement.java:36)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteDatabase.compileStatement(SQLiteDatabase.java:1145)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteDatabase.insertWithOnConflict(SQLiteDatabase.java:1536)
02-05 12:31:39.621: E/Database(274): at android.database.sqlite.SQLiteDatabase.insert(SQLiteDatabase.java:1410)
02-05 12:31:39.621: E/Database(274): at database.in.ProductDbHandler.addProducts(ProductDbHandler.java:64)
02-05 12:31:39.621: E/Database(274): at com.hellovx100.in.ClerkLogin.getItemsOfDept(ClerkLogin.java:110)
02-05 12:31:39.621: E/Database(274): at com.hellovx100.in.ClerkLogin.onCreate(ClerkLogin.java:92)
02-05 12:31:39.621: E/Database(274): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread.access$2300(ActivityThread.java:125)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
02-05 12:31:39.621: E/Database(274): at android.os.Handler.dispatchMessage(Handler.java:99)
02-05 12:31:39.621: E/Database(274): at android.os.Looper.loop(Looper.java:123)
02-05 12:31:39.621: E/Database(274): at android.app.ActivityThread.main(ActivityThread.java:4627)
02-05 12:31:39.621: E/Database(274): at java.lang.reflect.Method.invokeNative(Native Method)
02-05 12:31:39.621: E/Database(274): at java.lang.reflect.Method.invoke(Method.java:521)
02-05 12:31:39.621: E/Database(274): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
02-05 12:31:39.621: E/Database(274): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
02-05 12:31:39.621: E/Database(274): at dalvik.system.NativeStart.main(Native Method)
我在哪里做错了,请指导我。
任何帮助都会得到帮助。
编辑:我认为问题出在 josn 数据格式上,我得到"cat_id":["4","15"],"cat_name":{"4":"Mobile & Accessories","15":"Sports Fitness"}},我们如何在 json 中解析它,因为它就像数组中的数组。logcat 还在02-05 12:31:39.601 给出错误:I/Database(274): sqlite returned: error code = 1, msg = table tbProductDetails has no column named cat_id
如何处理此类问题