Android: Parsing large JSON file

后端 未结 2 1419
迷失自我
迷失自我 2020-12-12 06:28

I\'m creating an android application which should parse a Json from a file or url to a jsonarray and jsonobjects. The problem is that my json is 3.3 mb and when i use a simp

相关标签:
2条回答
  • 2020-12-12 07:12

    The hybrid streaming approach with Jackson is a good option. That way, you can advance a pointer through your raw JSON input (validating it as you go) and, when you detect an input chunk that needs to be processed, you can read it into a tree-hierarchy so that you can pull out any data you want from it.

    0 讨论(0)
  • 2020-12-12 07:24

    You should use json streaming either with gson or jackson. With Jackson you can use a hybrid approach as well. This would reduce your memory consumption significantly as only the portion of json being parsed is loaded into memory.

    https://sites.google.com/site/gson/gson-user-guide http://jackson.codehaus.org/

    A jackson example http://www.mkyong.com/java/jackson-streaming-api-to-read-and-write-json/

    0 讨论(0)
提交回复
热议问题