简体   繁体   English

处理大型JSON响应-Android

[英]Handling large json responses - Android

For a rest api call , I am getting a very large response and in some devices it is leading to OutOfMemory exception. 对于rest api调用,我得到一个非常大的响应,在某些设备中,这导致OutOfMemory异常。 Right now what I am doing is the response from http call is taken to a stringBuilder and then parsed to class using Gson. 现在我正在做的是将http调用的响应带到stringBuilder,然后使用Gson解析为类。 Is this the right way to do it? 这是正确的方法吗? Is there a better calling mechanism to avoid this memory error? 有没有更好的调用机制来避免此内存错误? How usually this kind of very large responses are handled in android? 在Android中通常如何处理这种很大的响应? Is there any other methods other than the normal HTTP call 除了正常的HTTP调用以外,还有其他方法吗?

Please help 请帮忙

I recomend you to use Jackson lib : http://wiki.fasterxml.com/JacksonDownload 我建议您使用Jackson库: http : //wiki.fasterxml.com/JacksonDownload

Jackson allow you to parse your inputStream or a file to Objects or Map directly, so you don't need to save your large JSON in a String or byte array to avoid memory error. Jackson允许您将inputStream或文件直接解析为Objects或Map,因此您无需将大型JSON保存在String或byte数组中就可以避免内存错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM