pom.xml
<!-- json simple -->
<dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
@PostMapping("/employees")
@ResponseBody
public Map<String,Object> employees(HttpServletRequest request, Model model) {
Map<String,Object> map = new HashMap<>();
try {
String file_path = "/Crawling/src/main/resources/templates/html/python_emp.json";
String path = request.getServletContext().getRealPath("/");
System.out.println("path:"+path);
File python_emp = new File(file_path);
FileInputStream fis = new FileInputStream(python_emp);
String str = new String(fis.readAllBytes());
JSONParser jsparse = new JSONParser();
System.out.println(str);
JSONArray jsArr = (JSONArray)jsparse.parse(str);
//JSONObject json = (JSONObject)jsparse.parse(str);
map.put("employees", jsArr);
} catch (Exception e) {
e.printStackTrace();
}
return map;
}