最近公司要解析一下无限层级的json,入库mysql,其一要求是,记录每个key,value及其所在层级目录,顶层目录从0开始计数。
package com.zichan360.bigdata.externalserviceapi; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.TypeReference; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; /** * @描述 json解析工具类 * @author chongmengzhao * */ public class JsonUtil{ private static Integer level=0; //当前层级 private static Integer currentLevel=0; //上一层级 private static Integer upperLevel=0; public static void main(String[] args) { String json = "{\n" + "\"id\":\"root\",\n" + "\"topic\":\"至尊借款\",\n" + "\"children\":[\n" + " {\"id\":\"a0\",\"topic\":\"1-3\",\"children\":[]},\n"