Optimization of JSON analysis on Android

I am developing an Android application that should receive an important amount of data from the JSON channel. This channel is a single line JSON file with a weight of about 400 ko, containing about 10 arrays that I need to get.

I use the JSON library for Android to do this, and the output works well, but it takes age (well, 30 seconds) to calculate. The loading step is quick, making JSON objects seem very long. Here are my steps (removing try / catch blocks, etc.).

JSONObject feed = new JSONObject(big_string_from_feed); JSONArray firstArray = feed.getJSONArray("key1"); JSONArray secondArray = feed.getJSONArray("key2"); 

[...]

And after I go through all my arrays to get each element as follows:

 for (int currentIndex =0;currentIndex<firstArray.length();currentIndex++){ JSONObject myObject = firstArray.getJSONObject(currentIndex); [....] } 

Is there something wrong with the way I do it? Is there a better way to do this?

Thank you in advance.

+4
source share
2 answers

If performance is a problem, use Jackson. See https://github.com/eishay/jvm-serializers/wiki for results. (These results should be updated soon to enable manual / tree-string processing in Jackson, which will have performance somewhere between Jackson manual and Jackson data-string processing. Manual / tree-string processing is the approach demonstrated in the original question .)

+2
source

Take a look at json-simple (see http://code.google.com/p/json-simple ). It provides a SAX-style parsing of JSON streams and is faster.

0
source

All Articles