Parse data about 3 MB in size with json in ANDROID?

I have to parse data on an HTTP request of about 3 MB in size through JSon, but the parser I use cannot do this. here is the json parser:

public static JSONObject getJSONfromURL(String url){ InputStream is = null; String result = ""; JSONObject jArray = null; //http post try{ HttpClient httpclient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(url); HttpResponse response = httpclient.execute(httppost); HttpEntity entity = response.getEntity(); is = entity.getContent(); }catch(Exception e){ // Log.e("log_tag", "Error in http connection "+e.toString()); } //convert response to string try{ BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),102400); StringBuilder sb = new StringBuilder(); String line = null; while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } is.close(); result=sb.toString(); }catch(Exception e){ // Log.e("log_tag", "Error converting result "+e.toString()); } try{ jArray = new JSONObject(result); }catch(JSONException e){ // Log.e("log_tag", "Error parsing data "+e.toString()); } return jArray; } 

Any help would be really appreciated. THANKS

+3
source share
1 answer

You parse a whole 3 MB line in memory. This causes a memory exception. Parsing big data in a stream:

+3
source

All Articles