java读取json文件
@Component
@Order(value = 1)
public class SystemData implements ApplicationRunner {
private static List<Map> coordinateSystem;
public static List getModelTree() {
return coordinateSystem;
}
private void jsonRead(InputStream file) {
ObjectMapper mapper = new ObjectMapper();
try {
List<Map> jsonMap = mapper.readValue(file, List.class);
coordinateSystem = jsonMap;
} catch (Exception e) {
System.err.println("转换出异常啦");
}
}
@Override
public void run(ApplicationArguments args) throws IOException {
ClassPathResource resource = new ClassPathResource("/Sdl.json");
InputStream fis = resource.getInputStream();
jsonRead(fis);
}
}
调用返回值:
SystemData.getModelTree()
json的位置: