开发者

Optimization of JSON parsing on Android

I'm developping an app for Android that needs to get an important amount of data from a JSON feed. This feed is a one line JSON file, weighting approx 400 ko, containing approximately 10 arrays that I need to get.

I'm using the JSON library for Android to do so, and the output works well, but it takes ages (well, 30 secs approx) to compute. The download step is done quickly, that's the creation of the JSON objects that seems to be very long. Here are my steps (removing try/catch blocks and so on).

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 every element the following way :

for (int cu开发者_如何学PythonrrentIndex =0;currentIndex<firstArray.length();currentIndex++){
    JSONObject myObject = firstArray.getJSONObject(currentIndex);
    [....]
}

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

Thank you very much in advance.


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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜