Android - Download JSON data and save to shared preferences

后端 未结 5 1038
遥遥无期
遥遥无期 2021-01-23 19:11

I\'m reading JSON data from a PHP Service and everytime the version of that JSON changes, I want to store it on Android (replace the old data with the new one), the JSON is used

相关标签:
5条回答
  • 2021-01-23 20:01

    It's fine to store it in shared preferences.

    0 讨论(0)
  • 2021-01-23 20:01

    It really depends on the data you want to store.

    SQLite

    Large amounts of same structured data should be stored in a SQLite database as databases are designed for this kind of data. As the data is structured and managed by the database, it can be queried to get a sub set of the data which matches certain criteria using a query language like SQL. This makes it possible to search in the data. Of course managing and searching large sets of data influences the performance so reading data from a database can be slower than reading data from SharedPreferences.

    SharedPreferences

    SharedPreferences is a key/value store where you can save a data under certain key. To read the data from the store you have to know the key of the data. This makes reading the data very easy. But as easy as it is to store a small amount of data as difficult it is to store and read large structured data as you need to define key for every single data, furthermore you cannot really search within the data except you have a certain concept for naming the keys.

    0 讨论(0)
  • 2021-01-23 20:01

    It's Depend on your data.

    • If your data should be dynamic and change frequently then you must use JOSN.
    • If YOUR data is not Not regular update and not a large size then store in shared preferance.
    • if your data large then store in database.

    Now you have to decide which one you select.

    0 讨论(0)
  • 2021-01-23 20:02

    Not a problem to save in shared preference..but keep in mind that SP mostly saves primitive data types in key value pair...and not an issue of 36kb in your case.:)

    0 讨论(0)
  • 2021-01-23 20:07

    if its a json String, having many records, values, then I would recommend to parse this string into records, and then save these records to sqlite, so that you wont need to parse this string again, and again, un-necessarily. otherwise, there isn't any issue in saving string into sharedpreferences.

    According to your data, you should opt for SQLite.

    0 讨论(0)
提交回复
热议问题