I am developing an android app. For this app i need to store some kind of data and access those data.
我正在开发一个Android应用程序。对于这个应用程序,我需要存储某种数据并访问这些数据。
What is the best way i can store data in the android app?
我可以在Android应用程序中存储数据的最佳方式是什么?
After saving somehow in android, When a user inset a value from the UI, app should look into the data set and check whether that value is in the data or not.
在android中以某种方式保存后,当用户从UI中插入一个值时,应该查看数据集并检查该值是否在数据中。
Please tell me how to do this in android.
请告诉我如何在android中执行此操作。
2 个解决方案
#1
1
You don't have to deal with the JSON Objects directly (althought you can if you want to). Have a look at the Gson library. It serializes and deserializes JSON data into objects and makes your life much easier!
您不必直接处理JSON对象(如果您愿意,也可以使用)。看看Gson图书馆。它将JSON数据序列化和反序列化为对象,让您的生活更轻松!
Additionally, since JSON Objects can be easily represented by strings, you can use Shared Preferences to store them in a key-value approach. If you end up using Gson, you can save your objects too using its toJson()
and fromJson()
methods.
此外,由于JSON对象可以通过字符串轻松表示,因此您可以使用“共享首选项”将它们存储为键值方法。如果最终使用Gson,则可以使用toJson()和fromJson()方法保存对象。
Note: If you do use SharedPreferences, remember that the user can manually delete the file via the device app manager.
注意:如果您确实使用SharedPreferences,请记住用户可以通过设备应用程序管理器手动删除该文件。
#2
#1
1
You don't have to deal with the JSON Objects directly (althought you can if you want to). Have a look at the Gson library. It serializes and deserializes JSON data into objects and makes your life much easier!
您不必直接处理JSON对象(如果您愿意,也可以使用)。看看Gson图书馆。它将JSON数据序列化和反序列化为对象,让您的生活更轻松!
Additionally, since JSON Objects can be easily represented by strings, you can use Shared Preferences to store them in a key-value approach. If you end up using Gson, you can save your objects too using its toJson()
and fromJson()
methods.
此外,由于JSON对象可以通过字符串轻松表示,因此您可以使用“共享首选项”将它们存储为键值方法。如果最终使用Gson,则可以使用toJson()和fromJson()方法保存对象。
Note: If you do use SharedPreferences, remember that the user can manually delete the file via the device app manager.
注意:如果您确实使用SharedPreferences,请记住用户可以通过设备应用程序管理器手动删除该文件。