在Java中遍历json树结构

public void listest(@RequestBody  String strjson) {
    List<String> ds =new ArrayList<String>();
    JSONObject json = JSONObject.parseObject(strjson);
    for (Map.Entry<String, Object> firstEntry : json.entrySet()) {
        String firstValue=firstEntry.getValue().toString();
        if(firstValue.isEmpty()){
            continue;
        }
        int i = jsonParseServices.testIsObject(firstValue);
        if (i==1){
            System.out.println("+++++++++++++++++++++++++++++"+firstEntry.getKey()+"+++++++++++++++++++++++++++++++++++++");
            listest(firstValue);
        }
        else {
            System.out.println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>"+firstEntry.getKey().toString()+"::::"+firstValue+"<<<<<<<<<<<<<<<<<<<<<<<<");
        }
    }
}

猜你喜欢

转载自blog.csdn.net/jiaowo_ccc/article/details/79759399