Noodles
Noodles

Reputation: 3273

Best practice to parse/manage a huge JSON file (~19MB) on Android

I have a huge JSON file to parse in my Android app. I suppose it is too big to parse it, probably the memory won't be enough. I usually parse just small file with GSON lib.

Is there a best practice for that? Or, do you suggest something to work it out?

Any suggestions is well appreciated.

Upvotes: 2

Views: 4167

Answers (3)

Jeshurun
Jeshurun

Reputation: 23186

If you use Jackson, make sure you use the streaming API instead of the databind API, then remember to use skipChildren() as agressively as possible. An example of using the streaming API is available here.

Upvotes: 1

Jesse Wilson
Jesse Wilson

Reputation: 40593

You're definitely going to need to use a streaming parser like JsonReader. It's available both in Gson (link) and in Android 3.0+ (link). You should use skipValue() aggressively since that avoids allocating objects that you aren't going to use.

Upvotes: 4

Umar Qureshi
Umar Qureshi

Reputation: 6115

For Parsing GSON is good where by making POJO you can parse JSON object to directly Java Object. and for the lengthy file you must do this in a separate thread i.e other than UI Thread For this You can Use AsyncTask a Utility for Managing thread. below is complete refrence to it

http://developer.android.com/reference/android/os/AsyncTask.html

Upvotes: 0

Related Questions