public void test2(){
//
System.out.println(" util");
String pactFile = "D:/**.json";
StringBuffer strbuffer = new StringBuffer();
Long id = Long.valueOf(0);// 1
String name = "";// 2
Long parentId = Long.valueOf(0);// 3
int lv = 0;// 4
File myFile = new File(pactFile);//"D:"+File.separatorChar+"**.json"
//!myFile.exists() !myFile.exists() true
if (!myFile.exists()) {
System.err.println("Can't Find " + pactFile);
}
JSONArray jsonArray = null;
try {
//
String input = FileUtils.readFileToString(myFile, "UTF-8");
// JSONObject
JSONObject jsonObject = JSONObject.fromObject(input);
if (jsonObject != null) {
//
jsonArray = jsonObject.getJSONArray("list");
System.out.println(jsonArray.size());
//jsonArray.size() json ( )
// jsonArray , map
for(int i = 0; i < jsonArray.size(); i++){
id = Long.valueOf(jsonArray.getJSONObject(i).get("id").toString());
name = jsonArray.getJSONObject(i).get("name").toString();
parentId = Long.valueOf(jsonArray.getJSONObject(i).get("parentId").toString());
lv = 0;
Map map =new HashMap();
map.put("id",id);
map.put("name",name);
map.put("parentId",parentId);
map.put("agencyId",lv);
//
sysRegionService.insert(map);
//
System.out.println(" :" + i);
}
}
} catch (Exception e) {
e.printStackTrace();
jsonArray = null;
}
System.out.println(" ");
}
}