33import com .alibaba .fastjson2 .JSON ;
44import com .alibaba .fastjson2 .JSONArray ;
55import com .alibaba .fastjson2 .JSONObject ;
6-
76import org .shirakawatyu .swust .entity .Course ;
8-
97import java .util .ArrayList ;
108import java .util .Collections ;
119import java .util .List ;
@@ -32,17 +30,22 @@ public static List<Course> toCourseList(String jsonString) {
3230 if ("" .equals (jsonString )) {
3331 courses .add (new Course ("今天没有课哦" , "好好休息吧" , "0-0" , 0 ));
3432 }else {
35- JSONArray objects = JSON .parseArray (jsonString );
36- for (int i = 0 ; i < objects .size (); i ++) {
37- JSONObject jsonObject = objects .getJSONObject (i );
38- courses .add (new Course (
39- jsonObject .getString ("jw_course_name" ),
40- jsonObject .getString ("base_room_name" ),
41- jsonObject .getString ("section_start" ) + "-" + jsonObject .getString ("section_end" ),
42- Integer .parseInt (jsonObject .getString ("section_start" ))
43- ));
33+ try {
34+ JSONArray objects = JSON .parseArray (jsonString );
35+ for (int i = 0 ; i < objects .size (); i ++) {
36+ JSONObject jsonObject = objects .getJSONObject (i );
37+ courses .add (new Course (
38+ jsonObject .getString ("jw_course_name" ),
39+ jsonObject .getString ("base_room_name" ),
40+ jsonObject .getString ("section_start" ) + "-" + jsonObject .getString ("section_end" ),
41+ Integer .parseInt (jsonObject .getString ("section_start" ))
42+ ));
43+ }
44+ Collections .sort (courses );
45+ } catch (Exception e ) {
46+ e .printStackTrace ();
47+ return null ;
4448 }
45- Collections .sort (courses );
4649 }
4750 return courses ;
4851 }
0 commit comments