I have a JSON Array that contains JSON Objects. Each JSON Object only has a simple key/value pairs (no nested array or something like that). For example:
[
{
"id": "01",
"name": "Zero One",
"desc": "Something about Zero One"
...
},
...
]
Values in those JSON Objects will be used later by the app.
Based on my limited experience, there are two easy ways to accomplish this:
- Parse the JSON ONCE at app startup and store ALL the objects in an
ArrayList(or anyListor even aMap) of POJOs.
My worry about using this method is memory usage and a relatively long waiting time. For example, if the JSON Array contains hundreds or even thousands of JSON objects, that means the app has to allocate hundreds/thousands of POJOs worth of memory, and I don't know how much or how I can calculate it exactly. Ideally, aHashMaporArrayMapis probably better for getting/accessing the value, but I read thatMapis even more memory hogging than a simpleList. - Parse the JSON only when the data is needed.
My worry about this method is maybe performance. I said "maybe" because I don't know exactly how taxing parsing a JSON file/string is. If I have to parse the JSON every time the app asks for it, then I essentially have to do a loop through the JSON Array, get the JSON Object, and check for a matchingid, to get thevalue.
Which one is better in terms of performance AND memory efficiency?
Is there an alternative that's even better than both?