package com.yeejoin.amos.boot.module.ymt.biz.utils;

import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.Resource;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Map;


public class JsonUtils {
    //将json文件转化为Map<list<Map<>>>
    public static Map getResourceJson(Resource resource) {
        String json = null;
        try {
            json = IOUtils.toString(resource.getInputStream(), String.valueOf(StandardCharsets.UTF_8));
        } catch (IOException e) {
            throw new RuntimeException(resource + "json文件转化失败");
        }
        return JSONObject.parseObject(json, Map.class);
    }
}
