现在的位置: 首页 > 综合 > 正文

java读取json格式文件以及相应的处理方式源码

2019年11月21日 综合 ⁄ 共 570字 ⁄ 字号 评论关闭

  //读取json文件地址

  /* String path = getClass().getClassLoader().getResource("menu.json").toString();

  path = path.replace("\\", "/");

  if (path.contains(":")) {

  path = path.replace("file:/", "");

  }*/

  ClassPathResource resource = new ClassPathResource("menu.json");

  File filePath = resource.getFile();

  JSONArray btnArray = null;

  //读取文件

  String input = FileUtils.readFileToString(filePath, "UTF-8");

  //将读取的数据转换为JSONObject

  JSONObject jsonObject = JSONObject.fromObject(input);

  if (jsonObject != null) {

  //取出按钮权限的数据

  btnArray = jsonObject.getJSONArray("btnList");

  }

  Map> btnMap = new HashMap<>();

  Iterator

抱歉!评论已关闭.