Student student =JSON.parseObject(jsonStr,Student.class);
List studentList = JSONObject.parseArray(jsonStr, Student.class);
HighSchool highSchool = JSON.parseObject(jsonStr,HighSchool.class);
List studentList = JSONObject.parseArray(highSchool.getStudent().toString(), Student.class);
首先要明白,以 { } 开头的是JSONObject,以 [ ] 开头的是JSONArray,如果本身就是json字符串的格式(即格式类型为String),那就不用转换,直接使用转换方法进行转换。
但是如果是嵌套字符串的话,从第一次转换后的java对象中取出来的是Object类型,这时候需要先用toString方法转换为String类型,然后再调用方法。
参考博文: