如何使用GSON解析JSONArray

时间:2013-01-21 07:42:30

标签: java android json gson

  

可能重复:
  Parsing a large json in android of 11 MB

我在使用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}]]}

我不知道我在哪里犯了错误。我因为文件的缺失而无效。

1 个答案:

答案 0 :(得分:1)

  

我在解析android中大约11MB的大型JSON时遇到了问题   与GSON和杰克逊合作。

下载和解析它将非常困难。 11MB太高了。

您可以使用的替代方案是:

  

您可以修改您的Web服务以使分区与Counter类似    counter=1,2,3.... 意味着以前1000记录的方式创建WS   在解析之后来计数器= 1另一个数据将来    counter = 2 并解析它等等..

这将帮助您解决问题一些方法。