我使用下面的代码来解析JSON字符串从网络获取,(30000条记录)的OutOfMemoryError而JSON解析Android中
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();
我收到OutOfMemory错误在下面的代码
while ((line = reader.readLine()) != null)
{
sb.append(line + "\n");
}
如何摆脱这个错误。当json字符串非常庞大时,会发生这种错误,因为它包含大约30,000条记录的数据。
在这方面的任何帮助,高度赞赏..
类似的问题在这里解决 http://stackoverflow.com/questions/6173396/parse-data-of-size-about-3mb-using-json-in-android?rq=1 – tdgtyugdyugdrugdr