如何保存从JSON数据SQLite中的机器人 [英] how to save data from json in sqlite in android

查看:120
本文介绍了如何保存从JSON数据SQLite中的机器人的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新的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.

<一个href="http://sourceforge.net/projects/ormlite/files/releases/com/j256/ormlite/">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.

这篇关于如何保存从JSON数据SQLite中的机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆