A
A
AlexDeww2018-05-03 20:46:05
Android
AlexDeww, 2018-05-03 20:46:05

Which should I choose to store JSON or sqlite data?

Data comes from the server in JSON format.

Example:
[
  {
    "currency_name": {
      "receive": "AFN",
      "send": "AED"
    },
    "name": "AFN",
    "denominations": [
      {
        "send_amount": "5",
        "receive_amount": "65",
        "order": "1"
      },
      {
        "send_amount": "10",
        "receive_amount": "130",
        "order": "2"
      },
      {
        "send_amount": "20",
        "receive_amount": "275",
        "order": "3"
      },
      {
        "send_amount": "50",
        "receive_amount": "725",
        "order": "4"
      },
      {
        "send_amount": "100",
        "receive_amount": "1500",
        "order": "5"
      },
      {
        "send_amount": "200",
        "receive_amount": "3250",
        "order": "6"
      }
    ]
  }
]


There are 5 types of such files with different data types. The average volume is 200 objects per file.
These files can arrive from once a day to once a month.
Actually the question arose how best to store them.
If you use files, then it will be easy to save them, but you will have to keep all the data in memory all the time.
If you use a database, you will have to bother with inserting data, but the memory is not full.
There are no complex samples for these data. Only 1 file can be changed on the device itself and sent back to the server.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey, 2018-05-04
@AlexDeww

About memory, look somehow in the studio how much the memory application takes. the amount of your data is trifles.
about how to store.
make everything easier. if there is no question (urgent) on optimization - do it simply. For example, often a few lines with gson are enough to parse json into objects. For room there are more lines. For pure sqlite, you already need to work hard.
Further. Premature optimization is evil. Now you don’t even know how your application will change and what bottlenecks it will have. Therefore, it is premature to complicate something like shooting blind.
Further. One hundred pounds that if the application is useful and will live long, then there will be changes. Therefore, the task is to break the application into more or less independent parts. How to do it. For example, you have a part that displays data and that provides data. And there is some agreement between them. This agreement is "formalized" in the application by the interface. For example a repository. Those. the first part uses the repository (via its interface). The other part provides the implementation of the repository. For example, through json text parsing.
This makes it possible, if necessary, to quickly replace the implementation of the repository so that it takes data from the database. Without changing anything else.
more or less like this)

A
alexalexes, 2018-05-03
@alexalexes

It is most efficient to store in a database.
You can then extract it even in JSON, even in XML, or display it on the web, whatever you like.
And parsing files is not writing requests. There is no flexibility in the parse.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question