import net.sf.json.JSONArray;import net.sf.json.JSONObject;import java.io.BufferedReader;import java.io.File;import java.io.FileReader;import java.io.IOException;public class JsonConvert {public static void main(String[] arg){// 读取原始json文件并进行操作和输出String s = ReadFile("./src/json.json");JSONArray first = JSONArray.fromObject(s);JSONArray newFirstArray = new JSONArray();for(int i=0;i<first.size();i++){JSONObject one = JSONObject.fromObject(first.get(i));JSONArray secondChild= JSONArray.fromObject(one.get("child"));JSONArray newSecondArray = new JSONArray();for(int j=0;j<secondChild.size();j++){JSONObject third= JSONObject.fromObject(secondChild.get(j));JSONArray thirdChild =(JSONArray) third.get("child");JSONArray newthirdArray = new JSONArray();for(int k =0;k<thirdChild.size();k++){JSONObject item = JSONObject.fromObject(thirdChild.get(k));String level =(String) item.get("level");if(Integer.parseInt(level)>4){}else{newthirdArray.add(item);}}third.put("child", newthirdArray);newSecondArray.add(third);}one.put("child", newSecondArray);newFirstArray.add(one);}System.out.println(newFirstArray.toString());}public static String ReadFile(String path) {File file = new File(path);BufferedReader reader = null;String laststr = "";try {reader = new BufferedReader(new FileReader(file));String tempString = null;while ((tempString = reader.readLine()) != null) {laststr = laststr + tempString;}reader.close();} catch (IOException e) {e.printStackTrace();} finally {if (reader != null) {try {reader.close();} catch (IOException e1) {}}}return laststr;}}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。