在11 MB的android解析一个大的JSON [英] Parsing a large json in android of 11 MB

查看:101
本文介绍了在11 MB的android解析一个大的JSON的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临的解析大约11MB的大JSON在Android中使用GSON和杰克逊的一个问题。问题是内存不足的错误发生异常,也堆大小不足以完成这一过程。 这是我的纸模型类

I am facing a problem in parsing a large JSON of about 11MB in android with GSON and Jackson. The issue is that out of memory error exception occurs and also heap size is not enough to accomplish this process. This is my Paper Model Class

public class Paper {

public int primaryKey;

public String title;

public int entry;

public Boolean favourite;

public String comment;

public int opt;

public int score;
}

这是我的响应模型类

public class Response {

public List<Paper> papers;

} 

这是我的JSON字符串

This is my JSON String

{"Paper":[[{"abstract":"Not Available","title":"A Fully Intraocular 0.0169mm<sup>2<\/sup>/pixel 512-Channel Self-Calibrating Epiretinal Prosthesis in 65nm CMOS","primaryKey":3,"entry":9,"score":-1,"comment":null,"favourite":false,"opt":1},{"abstract":"Not Available","title":"A Scalable 2.9mW 1Mb/s eTextiles Body Area Network Transceiver with Remotely Powered Sensors and Bi-Directional Data Communication","primaryKey":14,"entry":9,"score":-1,"comment":null,"favourite":false,"opt":1},{"abstract":"Not Available","title":"A 0.18µm CMOS SoC for a 100m-Range 10fps 200×96-Pixel Time-of-Flight Depth Sensor","primaryKey":20,"entry":9,"score":-1,"comment":null,"favourite":false,"opt":1},{"abstract":"Not Available","title":"A 12b 1.6GS/s 40mW DAC in 40nm CMOS with >70dB SFDR over Entire Nyquist Bandwidth","primaryKey":26,"entry":9,"score":-1,"comment":null,"favourite":false,"opt":1},{"abstract":"Not Available","title":"All-Digital Hybrid Temperature Sensor Network for Dense Thermal Monitoring","primaryKey":49,"entry":9,"score":-1,"comment":null,"favourite":false,"opt":1},{"abstract":"Not Available","title":"32Gb/s Data-Interpolator Receiver with 2-Tap DFE in 28nm CMOS","primaryKey":51,"entry":9,"score":-1,"comment":null,"favourite":false,"opt":1},{"abstract":"Not Available","title":"A 93% Efficiency Reconfigurable Switched-Capacitor DC-DC Converter Using On-Chip Ferroelectric Capacitors","primaryKey":60,"entry":9,"score":-1,"comment":null,"favourite":false,"opt":1},{"abstract":"Not Available","title":"A 45nm CMOS Near-Field Communication Radio with 0.15A/m RX Sensitivity and 4mA Current Consumption in Card Emulation Mode","primaryKey":61,"entry":9,"score":-1,"comment":null,"favourite":false,"opt":1}]]}

我不知道我做了一个错误。我得到空的论文的莉莎。

I don't know where i did a mistake. i getting null for the lise of papers.

推荐答案

使用流式解析,并尝试为你读它,整个输入已经被读取之前处理的内容。这样就可以避免在内存中保存完整结构。

Use a streaming parser and try to process the content as you read it, before the full input has been read. This way you can avoid to hold the full structure in memory.

例如,如果您输入JSON是一个巨大的数组,您可以通过元素处理输入元素。

For example if your input JSON is a huge array, you could process the input element by element.

这篇关于在11 MB的android解析一个大的JSON的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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