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

前端 未结 4 1406
情书的邮戳
情书的邮戳 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:22

    If possible only request parts of the data - this also reduces time for network io and thus saves battery.

    Otherwise you could try to not keep the incoming data in memory, but to 'stream' it onto the sd-card. When it is stored there you can then iterate over it. Most likely this will mean to use your own JSON tokenizer that does not build a full tree, but which is able to (like a SAX parser) only look at a part of the object tree at a time.

    You may have a look at Jackson, which has a streaming mode, which may be applicable.

提交回复
热议问题