如何保存从JSON数据SQLite中的机器人机器人、数据、JSON、SQLite

2023-09-04 23:15:26 作者:曾经永远只是曾经

我是新的Andr​​oid的编程,我想找到如何从JSON存储在sqlite的数据android.I没有发现它在互联网的任何有用的例子,这就是为什么我问here.If您展示我是一个简单的例子,我会很happy.Thanks很多!

I'm new in Android programming and I want to find how to store data from json in sqlite for android.I didn't find any useful examples of it in internet,that's why I'm asking here.If you show me a simple example of it I will be very happy.Thanks a lot!

推荐答案

创建具有您的JSON模式的属性。一个模型类

Create a model class that has the properties of your JSON model.

在模型中建立一个构造函数,它接受一个 org.json.JSONObject (搜索Android开发人员参考)。

Create a constructor in your model that accepts an org.json.JSONObject (Search the android developers reference).

在构造函数中,阅读的JSONObject 的值,你的物业,例如方法字符串optString() INT optInt()

In the constructor, read the values of the JSONObject to your properties with for example the methods String optString() and int optInt().

您也可以使用 ORMLite 为Android的对象保存到SQLite的。你可以找到工作的例子在这里:

You can also use ORMLite for Android to save the object to SQLite. You can find working examples here:

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

您需要在您的Andr​​oid项目导入ormlite核心和ormlite,机器人的.jar库。

You will need to import the ormlite-core and ormlite-android .jar libraries in your Android project.

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

ORMlite工作速度快,方便的接入方式。我已经用它多次在我的项目。

ORMlite works fast and has convenient access methods. I have used it multiple times in my projects.