OutOfMemoryError when using Gson to parse a large JSON response

前端 未结 3 1127
深忆病人
深忆病人 2021-02-10 22:42
URL url = new URL(\"http://pubapi.cryptsy.com/api.php?method=orderdatav2\");
CryptsyCurrencyPairsReturn response = gson.fromJson(new InputStreamReader(url.openStream()),         


        
3条回答
  •  眼角桃花
    2021-02-10 23:02

    Parsing large data in one-go is always tricky and troublesome. However Gson comes with some nice features to support that too.

    You should look for com.google.gson.stream.JsonReader to perform json parsing using streams. This will allow you to parse the data in an incremental order while its being downloaded and will spare devices from OutOfMemory errors.

    For more info, read this.

提交回复
热议问题