public static void main(String[] args) { try { List<String> lines = FileUtils.readLines(new File("d:/map.txt"), "utf-8"); StringBuilder stb = new StringBuilder(); for (String line : lines) { stb.append(line); } ArrayList<String> toLines = new ArrayList<String>(100); JSONArray jsonArray = JSONArray.fromObject(stb.toString()); for (int i = 0; i < jsonArray.size(); i++) { JSONArray citys = jsonArray.getJSONObject(i).getJSONArray("city"); for (int j = 0; j < citys.size(); j++) { JSONObject cityJson = citys.getJSONObject(j); String str = cityJson.getString("adcode")+","+cityJson.getString("name"); toLines.add(str); } } FileUtils.writeLines(new File("d:/map2.txt"),toLines); } catch (IOException e) { e.printStackTrace(); } }
java读取文档json类型数据, 并将数据存入文档
最新推荐文章于 2023-02-16 09:05:33 发布