内存不足的异常在解析Android中5MB JSON响应 [英] Out of memory exception while parsing 5MB JSON response in Android

查看:273
本文介绍了内存不足的异常在解析Android中5MB JSON响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到一个JSON响应的5MB,我下载和使用的字节数组,1024大小的StringBuffer保存。

I am getting 5MB of a JSON response, I am downloading and saving in StringBuffer using a byte array with 1024 size.

要解析这个反应,我必须创建一个JSONObject的参数为一个字符串。虽然转换成响应字符串,我得到一个内存溢出异常(stringBufferVar.toString())。

To parse this response, I have to create a JSONObject with the parameter as a String. While converting response into String, I am getting an out of memory exception(stringBufferVar.toString()).

从服务中,我将获得以下响应,因为每个连接codeD为Base64最大5MB的数据。5个附件的最大

From service I will get the following response as max of 5 attachments each of maximum 5MB data in Base64 encoded.

以下是从服务的响应。

{"result":[{"attachment":{"name":"one.doc", "type":"document", "data":"base64 encoded data max of 5MB"}, {"attachment":{"name":"two.txt", "type":"text", "data":"base64 encoded data max of 5MB"} }] }

我将显示在列表中的附件,当一个项目的用户点击我要保存该SD卡附件。对于这一点,我怎么能分析并保存大量的数据在JSON。

I will show the attachments in a list, when the user clicks on an item I have to save that attachment in SDCard. For this, how can I parse and save this huge amount of data in JSON.

请提供任何解决这个。

先谢谢了。

推荐答案

您需要使用一个基于流的解析器。在API 11+有 http://developer.android.com/reference/android /util/JsonReader.html

You need to use a Stream-based parser. in API 11+ there is http://developer.android.com/reference/android/util/JsonReader.html

下面,有GSON HTTP://$c$c.google。 COM / p /谷歌GSON /

此外,您可能需要保存为文件服务的响应与JsonReader重新打开它了。

Also, you probably need to save your service response as a file before reopening it with the JsonReader.

这篇关于内存不足的异常在解析Android中5MB JSON响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆