天津市建设工程质量协会网站,网站合同,wordpress文章分类跳转到指定模板,如何在修改wordpress1、功能场景 #xff08;1#xff09;多人合作开发一个功能模块时#xff0c;需要调用外部接口 #xff08;2#xff09;对方接口的开发工作还没有完成#xff0c;只能提供一个返回值的示例文件 json 文件。 #xff08;3#xff09;返回的 json 数据多达几百个字段。 …1、功能场景 1多人合作开发一个功能模块时需要调用外部接口 2对方接口的开发工作还没有完成只能提供一个返回值的示例文件 json 文件。 3返回的 json 数据多达几百个字段。 4为了本地测试方便需要读取 json 文件转换为 json 对象模拟对方返回数据。
2、功能代码 public void readJsonFile() {// 指定JSON文件路径String projectPath System.getProperty(user.dir);String modulePath /test20231019;String resourcePath /src/main/resources/;String fileName 接口返回值示例.json;String filePath projectPath modulePath resourcePath fileName;// 创建ObjectMapper对象ObjectMapper objectMapper new ObjectMapper();try {// 读取JSON文件并转换为JSON对象File file new File(filePath);JSONObject json objectMapper.readValue(file, JSONObject.class);// 打印JSON对象System.out.println(json);} catch (IOException e) {e.printStackTrace();}}