java读取resource下的json文件

在java-resource下新建一个paperTree.json的文件保存数据、采用Resource resource = new ClassPathResource读取方式、JSON.parseObject解析

 /**
     * 获取试卷类型树形菜单
     * @return
     */
    @PostMapping("/paperTree")
    public Resp<Object> paperTree() throws IOException {
        JSONArray arry = null;
        try {
            Resource resource = new ClassPathResource("paperTree.json");
            JSONObject json = JSON.parseObject(IOUtils.toString(new FileInputStream(resource.getFile())));
            arry = json.getJSONArray("list");
        } catch (IOException e) {
            e.printStackTrace();
        }
        return Resp.ok().setResult(arry);
    }

猜你喜欢

转载自blog.csdn.net/weixin_39709134/article/details/124864916