简体   繁体   English

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

[英]how to save data from json in sqlite in android

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! 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它的例子我会很高兴。非常感谢!

Create a model class that has the properties of your JSON model.创建一个 model class 具有您的 JSON Z20F35E630DAF44DBFA4C3F68F5Z39 的属性。

Create a constructor in your model that accepts an org.json.JSONObject (Search the android developers reference).在您的 model 中创建一个接受org.json.JSONObject的构造函数(搜索 android 开发人员参考)。

In the constructor, read the values of the JSONObject to your properties with for example the methods String optString() and int optInt() .在构造函数中,使用例如方法String optString()int optInt()JSONObject的值读取到您的属性中。

You can also use ORMLite for Android to save the object to SQLite.您还可以使用Android的 ORMLite 将 object 保存到 SQLite。 You can find working examples here:您可以在此处找到工作示例:

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

You will need to import the ormlite-core and ormlite-android.jar libraries in your Android project.您需要在 Android 项目中导入 ormlite-core 和 ormlite-android.jar 库。

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

ORMlite works fast and has convenient access methods. ORMlite 运行速度快,访问方式方便。 I have used it multiple times in my projects.我在我的项目中多次使用它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM