I need to get large amount of data (say 7000 records) from online database to Android application. While searching the web, I came to know that large amount of data will leads to outofmemory problem in json while convert from string. The solution was to convert the json with the help of gson or jackson. I have two question as follows
-
Another solution for converting json to avoid out of memory problem.
-
Shall I get the data in xml format? If so whether I can solve out of memory?
Edit
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");
}
I think xml format will allow you for large amount of data. I am developing a Project where I download approx 15000 data in xml and there is no a memory issue.