android - 在android中解析11MB的大json

标签 android json parsing jackson gson

我在使用 GSON 和 Jackson 解析 android 中约 11MB 的大 JSON 时遇到问题。问题是发生内存不足错误异常,并且堆大小不足以完成此过程。 这是我的纸模型类

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 字符串

{"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}]]}

我不知道我哪里做错了。我的论文列表为空。

最佳答案

在读取完整输入之前,使用流式解析器并尝试在读取内容时对其进行处理。这样您就可以避免将完整的结构保存在内存中。

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

关于android - 在android中解析11MB的大json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14412676/

相关文章:

android - 为什么 GPS_PROVIDER isProviderEnabled 的检查总是 "false"?

c# - MVC 4 中正确的 JSON 序列化

javascript - 如何将具有多个对象的 JSON 对象转换为一组对象

c# - JavaScriptSerializer.Deserialize - 如何更改字段名称

ios - 删除 NSString 中的 "jacknode"- iOS

android - 将 SQlite 与 MySql 同步

Android WiFi-Direct BroadcastReceiver 无法工作

java - 使用 Oauth 连接 Java 应用程序和 GAE 应用程序

java - 如何根据 Java 中指定的版本规范验证 json 模式

javascript - 如何解析网页中的JavaScript?