java读json文件

@RequestMapping("/jsontest")
    public String jsontest() {
        String path = getClass().getClassLoader().getResource("index.json").toString();
        path = path.replace("\\", "/");
        int indexOf = path.indexOf(":");
        path = path.substring(indexOf + 2);
        System.out.println(path);

        try {
            String input = FileUtils.readFileToString(new File(path), "UTF-8");
            JSONObject jsonObject = JSONObject.fromObject(input);
            System.out.println(jsonObject);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return "ok";

    }

import net.sf.json.JSONObject;

import org.apache.commons.io.FileUtils;

猜你喜欢

转载自blog.csdn.net/zflb2008/article/details/89326531