spring从resource中读取json数据

  1. import org.apache.commons.io.IOUtils;
  2. import org.springframework.core.io.ClassPathResource;
  3. ...
  4. ClassPathResource resource = new ClassPathResource("demo.json");
  5. String jsonStr = IOUtils.toString(resource.getInputStream(), StandardCharsets.UTF_8);
  6. JSONObject jsonObject = JSON.parseObject(jsonStr);
  7. ...