如何在android中的sqlite中保存json中的数据

har*_*ore 3 sqlite android json

我是Android编程的新手,我想找到如何在sqlite for android中存储来自json的数据.我没有在互联网上找到任何有用的例子,这就是为什么我在这里问.如果你告诉我一个简单的它的例子我会非常高兴.谢谢你们!

Wou*_*ter 8

创建一个具有JSON模型属性的模型类.

在模型中创建一个接受org.json.JSONObject(搜索android开发人员参考)的构造函数.

在构造函数中,JSONObject使用例如方法String optString()和方法读取属性的值int optInt().

您还可以使用ORMLite for Android将对象保存到SQLite.你可以在这里找到工作示例:

http://ormlite.com/docs/android-examples

您需要在Android项目中导入ormlite-core和ormlite-android .jar库.

http://sourceforge.net/projects/ormlite/files/releases/com/j256/ormlite/

ORMlite工作速度快,并且具有方便的访问方法.我在我的项目中多次使用过它.