com.alibaba fastjson1.2.47
//读取json文件 public static String readJsonFile(String fileName) { String jsonStr = ""; try { File jsonFile = new File(fileName); FileReader fileReader = new FileReader(jsonFile); Reader reader = new InputStreamReader(new FileInputStream(jsonFile),"utf-8"); int ch = 0; StringBuffer sb = new StringBuffer(); while ((ch = reader.read()) != -1) { sb.append((char) ch); } fileReader.close(); reader.close(); jsonStr = sb.toString(); return jsonStr; } catch (IOException e) { e.printStackTrace(); return null; } }
public static void main(String[] args) { String s = readJsonFile("I:\img\init.json"); JSonObject jobj = JSON.parseObject(s); System.out.println(jobj); String s1 = JSONObject.toJSONString(jobj); JSonObject que = jobj.getJSONObject("QUE");//构建JSONArray数组 System.out.println(que); try { //生成新的json文件 BufferedWriter bw = new BufferedWriter(new FileWriter( "I:\img\init1.json"));// 输出新的json文件 bw.write(s1); bw.flush(); bw.close(); } catch (IOException e) { e.printStackTrace(); } }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)