How do I parse a JSONArray in Java with Json.simple?

前端 未结 3 550
再見小時候
再見小時候 2020-12-30 04:35

I am trying to read a JSON file like this:

{
  \"presentationName\" : \"Here some text\",
  \"presentationAutor\" : \"Here some text\",
  \"presentationSlide         


        
3条回答
  •  梦谈多话
    2020-12-30 05:05

    For Gson you can paste your json file here : https://www.freecodeformat.com/json2pojo.php Create appropriate pojo classes and then use this code :

    Gson gson = new Gson();
    
        try (Reader reader = new FileReader("pathToYourFile.json")) {
    
            // Convert JSON File to Java Object
            Root root = gson.fromJson(reader, Root.class);
    
            // print staff you need
            System.out.println(root.getCommands().get(0).getName());
    
        } catch (IOException e) {
            e.printStackTrace();
        }
    

提交回复
热议问题