1

I issue some problems with my Apps code to read JSON files. So my App downloads the json files from my server and then uses this AsyncTask to read them.

This works fine for the smaller json file (about 2KB) but the big one (which is about 1.3MB in size) only loads the first lines.

I am not certainly sure what is causing the Problem, I tought about Strings not being able to store that much characters but then I read here that the maximum of Numbers is around 2 billion (which should not be exeeded by that json File). I hope you can help me! Thanks in advance!

Community
  • 1
  • 1
  • 2
    Post your Async Task task code, it is complicated to help without having that – Laurent Meyer Jun 04 '15 at 22:00
  • This may be a limitation of `android.util.Log` truncating your "printed" content, not necessarily a problem with your app not reading an entire file. If you are curious, try writing to file instead of `Log`. – akodiakson Jun 04 '15 at 22:46
  • Isn't that what I already do? Downloading the file in JSONDownloader and then reading from it in the JSONArrayAsyncTask? EDIT: Oh you mean the Debug Line? I'll try that. Thanks – Christian Oder Jun 05 '15 at 09:22
  • Hum intresting. If I log it to a file, I can see that the whole json file get read. However, this implies that something is wrong with the line where the JSONObject is getting created JSONObject obj = new JSONObject(stringBuilder.toString().trim()); as it does not reach the Log statement after the creating, however it ends the Async Task as my Progress Dialog Dissapears. – Christian Oder Jun 05 '15 at 09:37

3 Answers3

0

Based on Raghav's info here, and how it relates to Ted's info here, you're likely being limited by the available heap to your application.

Community
  • 1
  • 1
jwin
  • 41
  • 3
  • So there is no way to work around this? One should think I'm not the first person in the world who tries reading a 1.3MB JSON file in Android :( Also, when the file is 1.3MB, with a total length of 1,303,636 Characters, why doesnt it fit a 16MB Heap whichs max String lenght is 2,147,483,647 and instead only loads the first 4065 (according to a Log line in the Code) Characters? – Christian Oder Jun 05 '15 at 09:17
0

Working with big JSON files, you should persist the file and then read it.

I'm assuming that JSON files have much more information that a simple API HTTP request.

letz
  • 1,762
  • 1
  • 20
  • 40
0

I fixed my error. It was not caused by the String being to short, but by the JSON containing errors (which I did not expect, as it was created by an tool). Thanks for your help anyways! :)