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

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

    That JSON is huge!

    You definitely need to use a streaming JSON parser. There are two out there for Android: GSON and Jackson.

    GSON Streaming is explained at: https://sites.google.com/site/gson/streaming

    I like how GSON explains the problem you're having:

    Most applications should use only the object model API. JSON streaming is useful in just a few situations:

    When it is impossible or undesirable to load the entire object model into memory. This is most relevant on mobile platforms where memory is limited.

    Jackson Streaming is documented at: http://wiki.fasterxml.com/JacksonInFiveMinutes#Streaming_API_Example

提交回复
热议问题