我使用下面的代碼來解析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