File srcFile = new File( “D:/xxx.txt”);
if(!srcFile.exists())
return ;
String jsonString = null;
try {
jsonString = FileUtils.readFileToString(srcFile, "utf-8");
} catch (IOException e) {
logger.error(e.getMessage());
}
JSONArray jsonArray = JSONArray.fromObject(jsonString);
Object []objs = jsonArray.toArray();
String strs = "";
for(int i=0;i<objs.length;i++){
Map m = (Map)objs[i];
if(m.get("coding") == null)
continue;
String str = "'"+m.get("str").toString()+"'";
strs+= str;
if(i != objs.length-1){
codings +=",";
}
}
//执行完之后删除文件
if(srcFile.exists()){
srcFile.delete();
logger.info("文件已删除");
}
解析json数组文件
最新推荐文章于 2024-06-11 17:55:12 发布