2013-01-21 54 views
-2
解析JSONArray

可能重複:
Parsing a large json in android of 11 MB如何使用GSON

我面臨的一個問題,在分析大JSON關於與GSON和傑克遜的Android 11MB。問題是發生內存不足錯誤異常並且堆大小不足以完成此過程。這是我的紙模型類

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

我不知道我做了一個錯誤。我對文件的含義不了了之。

+0

11 MB的JSON在Android?它顯着更高,你爲什麼要分析如此大量的json? –

+0

@Pradeep此應用程序是一個脫機支持應用程序。我們將下載一次並從該文件解析。 – Praveen

+3

'Paper'''' papers'不一樣,如果您在Java部分將'papers'重命名爲'Paper',或者在JSON中將Paper更好地重命名爲'papers',那麼它很可能會更好。 – Alex

回答

1

我在解析GSON和Jackson的大約11MB的大JSON時遇到問題。

下載並解析它將非常困難。 11MB太高。

替代品,你可以使用方法是:

,你可以修改你的web服務,有一個像 counter=1,2,3.... meanse與計數器分區做一個WS的方式,首先1000個記錄 前來櫃檯= 1解析之後的另一個數據來找 計數器= 2並解析它等..

這將幫助你牛逼o解決你的問題一些方法。

+0

+1爲櫃檯部分 – TechSpellBound

+1

除了沒有理由這樣做。 Gson支持流式傳輸,就像其他JSON解析器一樣。 –