java: read json file
2022/1/7 12:33:24
本文主要是介绍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
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(); }
这篇关于java: read json file的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-12-24内网穿透资料入门教程
- 2024-12-24微服务资料入门指南
- 2024-12-24微信支付系统资料入门教程
- 2024-12-24微信支付资料详解:新手入门指南
- 2024-12-24Hbase资料:新手入门教程
- 2024-12-24Java部署资料
- 2024-12-24Java订单系统资料:新手入门教程
- 2024-12-24Java分布式资料入门教程
- 2024-12-24Java监控系统资料详解与入门教程
- 2024-12-24Java就业项目资料:新手入门必备教程