Java中使用json存储文件

时间:2022-07-28
本文章向大家介绍Java中使用json存储文件,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
// 方法一
JSONObject files = fiFeTaxVoucherFile.getFiles();
JSONArray oldFiles = new JSONArray((List<Object>) files.get("files"));
JSONArray newFiles = new JSONArray((List<Object>) request.getFiles().get("files"));
oldFiles.addAll(newFiles);
JSONObject jsonFiles = new JSONObject();
jsonFiles.put("files", oldFiles);
fiFeTaxVoucherFileModel.setFiles(jsonFiles);
FiFeTaxVoucherFileModel update = super.update(fiFeTaxVoucherFile);
// 方法二
JSONObject files = fiFeTaxVoucherFile.getFiles();
JSONArray oldFiles = new JSONArray((List<Object>) files.get("files"));
JSONArray newFiles = new JSONArray((List<Object>) request.getFiles().get("files"));
oldFiles.addAll(newFiles);
JSONObject jsonFiles = new JSONObject();
jsonFiles.put("files", JSON.toJSONString(oldFiles));
String file = JSON.toJSONString(jsonFiles);
fiFeTaxVoucherFileModel.setFiles(JSON.parseObject(file));
FiFeTaxVoucherFileModel update = super.update(fiFeTaxVoucherFile);

推荐使用方法一