package com.kidgrow.order.utils; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import org.apache.commons.io.IOUtils; import org.springframework.core.io.ClassPathResource; import java.io.IOException; import java.io.InputStreamReader; import java.nio.charset.Charset; import java.util.LinkedHashMap; import java.util.Map; /** * 石家庄喜高科技有限责任公司 版权所有 © Copyright 2020
* * @Description:
* @Project:
* @CreateDate: Created in 2020/4/4 12:48
* @Author: liuke */ public class JsonUtils { public static JSONObject readJsonFromClassPath(String path) throws IOException { ClassPathResource resource = new ClassPathResource(path); if (resource.exists()) { String areaData = IOUtils.toString(resource.getInputStream(), Charset.forName("UTF-8")); return (JSONObject)JSON.parse(areaData); } else { throw new IOException(); } } public static Map getMap(String path){ Map map = new LinkedHashMap(); try { //路径 ClassPathResource classPathResource = new ClassPathResource(path); //读取文件信息 String str = IOUtils.toString(new InputStreamReader(classPathResource.getInputStream(),"UTF-8")); //转换为Map对象 map = JSONObject.parseObject(str, LinkedHashMap.class); } catch (Exception e) { e.printStackTrace(); } return map; } }