使用的是fastjson

//json数组字符串转List<JavaBean>
String str = "[{"journeyDate":"2021-07-01","journeyWay":"1","travelToolNo":"122","goPlace":"北京","toPlace":"惠州"},{"journeyDate":"2021-07-04","journeyWay":"1","travelToolNo":"123","goPlace":"惠州","toPlace":"北京"}]"; List<SojournHistory> arr = (List<SojournHistory>) JSON.parseObject(str,new TypeReference<ArrayList<SojournHistory>>() {}); System.out.println(arr.get(0).getToPlace());

这里再扩展一下fastjson涉及到的常用方法

//json字符串转json对象
String str = "{"name":"aa","high":172}"; JSONObject jsonObject = JSON.parseObject(str); JSONObject jsonObject1 = JSONObject.parseObject(str);
System.out.println(jsonObject.getString("name")+":"+jsonObject.getInteger("high"));
//json数组字符串转JsonArray
String str = "[{"name":"aa","high":172},{"name":"bb","high":175}]"; JSONArray ja = JSON.parseArray(str); JSONArray js = JSONArray.parseArray(str); System.out.println(ja.getJSONObject(0).getString("name"));
//json字符串转JavaBean
String str = "{"name":"aa","high":172}"; Student student = JSON.parseObject(str, new TypeReference<Student>() {}); Student student1 = JSONObject.parseObject(str, new TypeReference<Student>() {}); System.out.println(student.getName()+":"+student.getHigh());
//json字符串转List<JavaBean>
String str = "[{"name":"aa","high":172},{"name":"bb","high":175}]"; List<Student> arr = (List<Student>) JSON.parseObject(str,new TypeReference<ArrayList<Student>>() {}); List<Student> arrs = JSONArray.parseObject(str, new TypeReference<ArrayList<Student>>() {}); System.out.println(arr.get(0).getName());