0

https://stackoverflow.com/questions/6955657/ I read this question . But i don't want to upload my file . Because the content is from my client so i cannot upload it without permissions. so i want to check it locally. I have written a java program , it takes too much of time to read 37mb file . But it didn't get succeeded . My program is

 try 
    { 
        new JSONObject(filecontent);
        System.out.println("valid file");
    } 
    catch(JSONException ex)
    {
            System.out.println("Invalid file");
    }


    {
        try
        {
            new JSONArray(filecontent);
            System.out.println("valid file");
        }
        catch(JSONException ex)
        {
            System.out.println("Invalid file");
        }
    }

But i googled it to do it quickly . Does php [with the help of file_get_contents and json_decode] give better solution or can i implement it in java itself? please help me to do it locally quickly.

Community
  • 1
  • 1
Gibbs
  • 21,904
  • 13
  • 74
  • 138
  • What library are you using to read the JSON? – Boris the Spider Apr 17 '14 at 09:35
  • @Spider, I am using this one . https://github.com/douglascrockford/JSON-java – Gibbs Apr 17 '14 at 09:37
  • P.S. you code is decidedly weird. First you set `flag = false` then, in the next line, you test `if(flag)` - which can **never** be `true` at this point. Moreover the message you emit if `flag` were `true` seems to be the message for `false`. Next you have an `if(flag == false)` which is just horrible - what's wrong with `if(!flag)`? – Boris the Spider Apr 17 '14 at 09:38
  • 1
    Well, don't use some strange library you found somewhere, use [Jackson](http://jackson.codehaus.org/) or [GSON](https://code.google.com/p/google-gson/). There are numerous performance comparisons - like [this one](http://blaazinsoftwaretech.blogspot.co.uk/2013/08/jackson-2-vs-gson-performance-comparison.html) – Boris the Spider Apr 17 '14 at 09:40
  • Thanks Spider , I ll try Jackson .. Its not my full implementation. pls dont confuse with flags. just or debuging purposes. yeah if(!flag) is good. – Gibbs Apr 17 '14 at 09:42
  • 2
    I dont see any way to pass streaming data to JSONObject of json.org. However GSON has streaming option. You could give it a try http://stackoverflow.com/questions/9390368/java-best-approach-to-parse-huge-extra-large-json-file – Hirak Apr 17 '14 at 09:43
  • @user3168736 don't post code up and then tell us to **ignore bits of it**. This is grossly unhelpful. Firstly it implies that you have posted more code than necessary and secondly it implies that I have just wasted 5 minutes trying to work out what's going on. This is very bad etiquette. – Boris the Spider Apr 17 '14 at 09:48

0 Answers0