|
@@ -49,6 +49,29 @@ public class JsonResourceUtil {
|
|
return json;
|
|
return json;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ //json文件转化为JSONArray
|
|
|
|
+ public static JSONArray getJsonArrFromResource(String filename) {
|
|
|
|
+ JSONArray json = null;
|
|
|
|
+ if (!filename.contains(".json")) {
|
|
|
|
+ filename += ".json";
|
|
|
|
+ }
|
|
|
|
+ try {
|
|
|
|
+ ClassPathResource classPathResource = new ClassPathResource(filename);
|
|
|
|
+ if (classPathResource.exists()) {
|
|
|
|
+ InputStream inputStream = classPathResource.getInputStream();
|
|
|
|
+ String content = IOUtils.toString(inputStream, StandardCharsets.UTF_8);
|
|
|
|
+ json = JSON.parseArray(content);
|
|
|
|
+ } else {
|
|
|
|
+ logger.info("file not exist!");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ logger.info("readFileToString" + e.getMessage());
|
|
|
|
+ }
|
|
|
|
+ return json;
|
|
|
|
+ }
|
|
|
|
+
|
|
public static Map<String, Map<String, Object>> jsonToMap(Object jsonObj) {
|
|
public static Map<String, Map<String, Object>> jsonToMap(Object jsonObj) {
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonObj.toString());
|
|
JSONObject jsonObject = JSONObject.parseObject(jsonObj.toString());
|
|
Map<String, Map<String, Object>> mapMap = new HashMap<>();
|
|
Map<String, Map<String, Object>> mapMap = new HashMap<>();
|