Java/Android: java.lang.OutOfMemoryError while building a JSON object

前端 未结 4 1404
情书的邮戳
情书的邮戳 2020-12-16 22:46

I am importing JSON data from a public database URI http://data.seattle.gov/api/views/3k2p-39jp/rows.json and the rows go as far as 445454. Using the following code I am co

4条回答
  •  无人及你
    2020-12-16 23:02

    Streaming pull parser is the way. I recommend GSON, as this has small memory footpring (just pull parsing is about 16K , jackson is way bigger)

    Your code is problematic because you allocate:

    • buffer to hold all the string data coming from service
    • all the JSON DOM objects

    and this is slow, and gives you memory meltdown.

    In case you need java objects out of your JSON data , you may try my small databinding library building on GSON (shameles self advertising off):

    https://github.com/ko5tik/jsonserializer

提交回复
热议问题