List<JSONObject> list = new ArrayList<>();
cn.hutool.json.JSONObject json = JSONUtil.readJSONObject(new File("D:\\work\\doc\\友创汽车服务平台\\需求\\areaData.json"), Charset.forName("UTF-8"));
json.forEach(e -> {
cn.hutool.json.JSONObject jsonObject = (cn.hutool.json.JSONObject) e.getValue();
AtomicInteger i = new AtomicInteger();
jsonObject.forEach(j -> {
JSONObject areaJson = new JSONObject();
areaJson.put("parentCode", e.getKey());
areaJson.put("code", j.getKey());
areaJson.put("name", j.getValue());
areaJson.put("sort", i.incrementAndGet());
String type = e.getKey().replaceAll("0*$", "");
if ("86".equals(e.getKey())) {
type = "AreaType_province";
} else if (type.length() == 2) {
type = "AreaType_city";
} else {
type = "AreaType_country";
}
areaJson.put("type", type);
list.add(areaJson);
});
});
System.out.println(list.size());
// 通过工具类创建writer
ExcelWriter writer =
ExcelUtil.getWriter("D:\\singon_file\\export_excel_1qaz2wszx3edc\\area.xlsx");
writer.write(list);
writer.close();
System.out.println("导出成功!");
解析json文件获取数据,数据来源:微信