【问题标题】:How to Parse JSONArray using GSON [duplicate]如何使用 GSON 解析 JSONArray [重复]
【发布时间】:2013-01-21 07:42:30
【问题描述】:

可能重复:
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}]]}

我不知道我在哪里做错了。我的论文数为空。

【问题讨论】:

  • Android 中的 11 MB JSON?它明显更高,您为什么要尝试解析如此大量的 json?
  • @Pradeep 此应用程序是离线支持应用程序。我们将下载一次并从该文件中解析。
  • Paperpapers 不一样,如果您在 Java 部分将 papers 重命名为 Paper,或者在 JSON 中将 Paper 重命名为 papers 更好,则有很有可能它会更好地工作。
  • 你需要发布代码,你正在解析它

标签: java android json gson


【解决方案1】:

我在 android 中解析大约 11MB 的大型 JSON 时遇到问题 与 GSON 和 Jackson。

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

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

您可以修改您的 Web 服务,使其具有一个带有 Counter 的分区,例如 counter=1,2,3.... 表示以前 1000 条记录的方式制作 WS 解析后为 counter=1 来获取另一个数据 counter=2 并解析它等等..

这将帮助您解决问题。

【讨论】:

  • 除非没有理由这样做。 Gson 支持流式传输,其他 JSON 解析器也是如此。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-12
  • 2023-04-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多