代码如下:
@RequestMapping("/add")
public JSONArray add() {
System.out.println("进入Student_controller_add");
Map map = new HashMap();
List<Teacher_Course> all = studentService.getAll();
System.out.println("List对象的值:"+all);
map.put("result", all);
map.put("totla", all.size());
map.put("msg", "这是数据传来的!");
map.put("code",200);
// String result = JSON.toJSONString(map);
// System.out.println("方案一:" + result);
JSONArray jsonArray = new JSONArray();
jsonArray.add(map);
System.out.println("方案二:" + jsonArray.toJSONString());
return jsonArray;
}
控制台输出的json如下:
List对象的值:[Teacher_Course(tid=null, tname=li, tphone=null, tpwd=null, cno=tx20210909, cnum=tx20210909.2018240206, cname=操作系统, ctype=专业课, cdept=信息学院, ctno=null, cyear=2021, cterm=1, cclass=2018240206, cgrade=null)]
方案二:[{"result":[{"cclass":"2018240206","cdept":"信息学院","cname":"操作系统","cno":"tx20210909","cnum":"tx20210909.2018240206","cterm":1,"ctype":"专业课","cyear":"2021","tname":"li"}],"msg":"这是数据传来的!","code":200,"totla":1}]
请问,怎么在前端获取json的值,谢谢!