GSON

2013-01-21 3 views
-2
를 사용하여 JSONArray를 구문 분석하는 방법

가능한 중복 :
Parsing a large json in android of 11 MBGSON

내가 GSON 잭슨과 안드로이드에서 11메가바이트에 대해 큰 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}]]} 

나도 몰라입니다. 서류가 많으면 널 null이됩니다.

+0

안드로이드에서 11 MB의 JSON? 그것은 상당히 높습니다. 당신은 왜 많은 양의 JSON을 파싱하려고합니까? –

+0

@Pradeep이 어플은 오프라인 지원 애플리케이션입니다. 우리는 한 번 다운로드하고 해당 파일을 구문 분석합니다. – Praveen

+3

'Paper'와'papers'는 동일하지 않습니다. 자바 부분에서'papers'를'Paper'로 바꾸거나 JSON에서'Paper'를'papers'로 바꾼다면 더 잘 될 가능성이 큽니다. – Alex

답변

1

GSON과 Jackson과 함께 android에서 약 11MB의 큰 JSON을 구문 분석 할 때 문제가 있습니다.

다운로드 및 구문 분석이 매우 어려울 것입니다. 11MB가 너무 높습니다. 당신이 사용할 수있는

대안이다 : 당신이 당신의 Webservice를 수정 할 수

먼저 1000 개 레코드 카운터 = 1 이리 하는 방법으로 WS를 확인 counter=1,2,3.... meanse 같은 카운터와 파티션을 가지고 그것을 구문 분석 후 다른 데이터는이 당신에게 t 도움이 될 것입니다

.. = 카운터 2 올 등등을 구문 분석합니다 o 문제 해결 방법.

+0

+1에 대한 카운터 부분 – TechSpellBound

+1

제외 할 이유가 없습니다. Gson은 다른 JSON 파서와 마찬가지로 스트리밍을 지원합니다. –