1

I want to parse json file as input and my code is

public static void getjsonfile() {
    // TODO Auto-generated method stub
    JsonParser parser = new JsonParser();
    Object obj = null;
    try {
        obj = parser.parse(new FileReader("c:\\json\\jsonfile"));
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    JSONObject jsonObject = (JSONObject) obj;
    System.out.println("Json" + jsonObject);
}

I am using java 4. So JsonParser is not working... Is there any other way to get the JSON?

ernest_k
  • 44,416
  • 5
  • 53
  • 99
Shini
  • 51
  • 7
  • 4
    switch to java8?:) – andrew17 Jan 14 '20 at 12:44
  • 1
    What do you mean by "Java 4"? Do you mean Java 1.4, an ancient Java version from 2002? Why are you using such an ancient version? – Jesper Jan 14 '20 at 12:45
  • no...i want to do in java4..yes..1.4.. – Shini Jan 14 '20 at 12:45
  • Go through the list of Java JSON libraries and try to find one that still works in Java 1.4 (possibly an older version of the library). https://stackoverflow.com/questions/2591098 – Thilo Jan 14 '20 at 12:46
  • have you tried gson parser ? – Muhammad Azam Jan 14 '20 at 12:46
  • There is no support for JSON in Java 1.4 and any library you can find for working with JSON will likely not work on Java 1.4 because it's just too old. – Jesper Jan 14 '20 at 12:46
  • What's the exception that have you encountered, – Karim Jan 14 '20 at 12:48
  • is there any method to get the json in java 1.4 – Shini Jan 14 '20 at 12:48
  • Since JSON spec was initially published in 2002 and later revised in 2017, and Java 4 published in 2002, I don't think you gonna find libraries that will support java 4, you ganna have to parse yourself – Karim Jan 14 '20 at 12:50
  • Take the sources of a json liberary, so you can backport them; strip generics and so on. Then at least you have the hope being compatible with a less historic version. If 1.4 is imposed by some JVM on some platform (like cards), seek to escape that, be for instance generating java 1.4 code from a higher level java. – Joop Eggen Jan 14 '20 at 13:02

0 Answers0