我需要從在線數據庫獲取大量數據(比如7000條記錄)到android應用程序。雖然谷歌搜索,我知道大量的數據會導致JSON的內存問題,同時從字符串轉換。解決方案是在gson或jackson的幫助下轉換json。我有兩個問題如下如何從web服務中檢索大數據到Android,無需外部存儲
其他任何解決方案轉換JSON以避免內存不足問題。
我應該用xml格式獲取數據嗎?如果是的話,我能否解決內存不足?
請幫助我..我很緊急。
編輯:
String result = convertStreamToString(is);
JSONObject jObject = new JSONObject(result); // Only i am getting outofMemory Exception..
private static String convertStreamToString(InputStream inputStream)
throws IOException {
ByteArrayOutputStream out = new ByteArrayOutputStream();
InputStream in = new BufferedInputStream(inputStream);
byte[] buffer = new byte[1024];
int n = 0;
try {
while (-1 != (n = in.read(buffer))) {
out.write(buffer, 0, n);
}
} finally {
out.close();
in.close();
}
return out.toString("UTF-8");
}
創建一個POJO類並使用JSON添加數據。在這種情況下,我認爲JSON不會造成內存不足。 – 2011-12-30 04:58:57
有多少列7000條記錄?由於易於轉換爲對象,我更喜歡JSON over XML的數據傳輸。就數據負載而言,XML和JSON都佔用幾乎相同的內存。 – kosa 2011-12-30 05:03:44
@thinksteep近15列。 – deepa 2011-12-30 05:05:13