Json串跟上一个博客的json保持一致
public class Test{
public static void main(String[] args) {
String jsonStr = "";
JSONObject jsonObject = JSONObject.parseObject(jsonStr);
JSONArray jsonArray = new JSONArray(); // 所有叶子
JSONObject rootJson = jsonObject.getJSONObject("data");
Test test = new Test();
test.hasChildren(rootJson, jsonArray);
}
public void hasChildren(JSONObject json,JSONArray jsonArray){
boolean flag = json.containsKey("children");
if (flag) {
JSONArray array = json.getJSONArray("children");
for (Object object : array) {
JSONObject jo = (JSONObject) object;
hasChildren(jo,jsonArray);
}
} else {
jsonArray.add(json);
}
}
}