I use the code below to parse a JSON string extracted from the Internet (30,000 entries)
DefaultHttpClient httpclient = new DefaultHttpClient(new BasicHttpParams()); HttpPost httppost = new HttpPost(params[0]); httppost.setHeader("Content-type", "application/json"); InputStream inputStream = null; String result = null; HttpResponse response = null; try { response = httpclient.execute(httppost); } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } HttpEntity entity = response.getEntity(); try { inputStream = entity.getContent(); } catch (IllegalStateException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } BufferedReader reader = null; try { reader = new BufferedReader(new InputStreamReader(inputStream, "UTF-8"),8); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } StringBuilder sb = new StringBuilder(); String line = null; try { while ((line = reader.readLine()) != null) { sb.append(line + "\n"); } } catch (IOException e) { e.printStackTrace(); } result = sb.toString();
I get an OutofMemory error in the code below
while ((line = reader.readLine()) != null) { sb.append(line + "\n"); }
How to get rid of this error. This error occurs when the json string is very large, as it contains data about 30,000 records.
Any help in this regard is much appreciated.
source share