Problem with large size JSON on android

Asked

Viewed 431 times

2

I am receiving a JSON file from a Webservice, this file comes with the approximate size of 5.7M, ai ai quando eu converter seu conteúdo para Jsonarray usando a biblioteca Gson, ele apresenta me o erro:

com.google.gson.JsonSyntaxException: com.google.gson.stream.MalformedJsonException: Unterminated string at line 1 column 4045314

however the file is correct, when I file the same file with a slightly smaller amount of content (1.8M) to routine works normally, someone has knowledge of why this occurs, there is some known solution ?

Follows the code used:

 JsonParser  parser = new JsonParser();
 JsonElement elem   = parser.parse( json.getString("webservice") ); //O erro ocorre aqui;
 JsonArray resultado2 = elem.getAsJsonArray();
 int len = resultado2.size();

Guys, I’m sorry to everyone. I found the problem. The file was coming from corrupted not downloading completely, when I checked the file had seen what the system generated me, not what the tablet downloaded.

I apologize and I appreciate the support of everyone here.

  • Have you tried using this http://www.json.org/javalibrary/?

  • Yes, it was the one I used before and gave a similar error, so I tried with gson because I saw that solved some cases.

  • For performance I recommend the library Jackson, for Android has the jackson-jr (https://github.com/FasterXML/jackson-jr).

  • put the code you are using to convert. It can be optimized.

  • Ready edited the question and put the code, @Wakim am reading about it now.

  • 1

    Maybe it’s the case that you think about paging this file?

  • So I would also do the same Onosendai only that it is not mine the file comes from another system, and they can not do anything to paginate me the file because the service is used by other applications.

  • @Hiagosouza Do you have at your disposal a server? One possibility would be to implement a parser there that will make the pagination for you.

  • So, the goal is to use the existing resource for the other applications, that is, the same server provides the information to the other applications, but if I need to allocate a server just to do this the project will become unviable ('expensive') for the final client. I’m trying to do the whole procedure on the tablet and to finish would just need to finish this part. He converting to the object I believe the rest of the routine will work normally. Note: I’m testing the Stringreader @Eduardo Oliveira sent. I want to give you an answer as soon as I’m done.

  • There was no actual programming error.

  • No, there was no @utluiz.

Show 6 more comments

1 answer

0

I’m gonna kick it, I don’t know if it’ll do the trick.

The parse method also accepts a Reader as parameter. Try to encapsulate the String in a Stringreader and then parse:

JsonParser  parser = new JsonParser();

StringReader reader = new StringReader(json.getString("webservice"));

JsonElement elem   = parser.parse(reader);
JsonArray resultado2 = elem.getAsJsonArray();
int len = resultado2.size();
  • I’ll try, thank you. I’ve come to tell you if it worked.

  • I tried your suggestion but now it falls in the catch and the Exeception comes as "null".

  • In your original code, where exactly did the error occur? Here json.getString("webservice") or here parser.parse(...)?

  • in parser.parse. Jsonelement elem = parser.parse(...);

  • It doesn’t make much sense. Can you paste the json content generated on the jsonlint.com site? Let’s make sure the content is ok. :)

  • I tried and there I can not paste, because it is too big the file, then I tried to validate by http://jsonformatter.curiousconcept.com/ that it picks up by the url. And in him everything is ok.

  • Could it somehow be bursting with memory ?

  • What if you tried to read directly from the stream? http://stackoverflow.com/questions/16902425/load-very-heavy-stream-with-gson

  • I believe what’s happening is that it’s bursting with memory.

Show 4 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.