读取json文件的结果利用fastjson进行转换为json对象或集合进行操作
依赖的fastjson包
<dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>2.0.17</version> </dependency>
实现代码:
//读取json文件 String path="D:\\home\\result.json"; InputStream in=new FileInputStream(path); BufferedReader reder=new BufferedReader(new InputStreamReader(in)); StringBuilder builder=new StringBuilder(); String line; while((line=reder.readLine())!=null) { builder.append(line); } reder.close(); //将结果转为json对象 String json= builder.toString(); JSONObject jsonObject=JSONObject.parseObject(json);
标签:reder,Java,读取,json,JSON,new,line,String From: https://www.cnblogs.com/yinhao686/p/17858909.html