Reputation: 3273
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
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
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
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