• java: read json file


    https://commons.apache.org/proper/commons-io/download_io.cgi
    https://commons.apache.org/proper/commons-io/apidocs/org/apache/commons/io/FileUtils.html
    https://stleary.github.io/JSON-java/org/json/JSONObject.html
    https://github.com/stleary/JSON-java

    HttpClient 5.1.2
    https://hc.apache.org/downloads.cgi

     try {
                    String filename = "geovindu.json";
                    InputStream is = SqlDuMain.class.getResourceAsStream(filename);
                    JSONTokener tokener = new JSONTokener(is);
                    JSONObject object = new JSONObject(tokener);
                    System.out.println("Id  : " + object.getLong("id"));
                    System.out.println("Name: " + object.getString("name"));
                    System.out.println("Age : " + object.getInt("age"));
    
                    System.out.println("Courses: ");
                    JSONArray courses = object.getJSONArray("courses");
                    for (int dui = 0; dui < courses.length(); dui++) {
                        System.out.println("  - " + courses.get(dui));
                    }
    
                   /*Geovin Du*/ //2
                    File file=new File("src/geovindu.json");
                    if (file.exists()) {
    
                        String content = FileUtils.readFileToString(file, "UTF-8");
    
                        System.out.println(content);
                        //String filename1 = "geovindu.json";
                        JSONObject jsonObject = parseJSONFile("src/geovindu.json");
                        System.out.println(jsonObject.toString());
    
                    }
    
    
    
    
                }
                catch (Exception exception)
                {
                    exception.printStackTrace();
                }
    
    
    
            }
            catch (NoSuchMethodException exception)
            {
                exception.printStackTrace();
            }
            catch (Exception exception){
                exception.printStackTrace();
            }
    

      

    哲学管理(学)人生, 文学艺术生活, 自动(计算机学)物理(学)工作, 生物(学)化学逆境, 历史(学)测绘(学)时间, 经济(学)数学金钱(理财), 心理(学)医学情绪, 诗词美容情感, 美学建筑(学)家园, 解构建构(分析)整合学习, 智商情商(IQ、EQ)运筹(学)成功.---Geovin Du(涂聚文)
  • 相关阅读:
    day12-html(css)
    day-12- 前端 html
    python-day11 pymysql
    day11-mysql 练习题
    python-day11 Mysql 数据类操作
    python-day11 Mysql 数据类型
    python-day11-MYSQL 数据库及数据表
    最简单的checkbox, radio跟文字在一行
    前端压缩
    table td 设置宽高无效的问题
  • 原文地址:https://www.cnblogs.com/geovindu/p/15774575.html
Copyright © 2020-2023  润新知