JSON与List转换
fastJson
//list -> json
List<Student> list = new ArrayList<Student>();
String str=JSON.toJSON(list).toString();
//json -> list
List<Student> list = new ArrayList<Student>();
list = JSONObject.parseArray(jasonArray, Student.class);
Gson
//list -> json
Gson gson = new Gson();
List<Student> students = new ArrayList<Student>();
String str = gson.toJson(students);
//json -> list
Gson gson = new Gson();
List<Student> students = gson.fromJson(str, new TypeToken<List<Student>>(){}.getType());
JsonObject obj = JSON.parseObject(res);
List<StudentDto> nodeAttrs = new Gson().fromJson(obj.get("data"), new TypeToken<List<StudentDto>>(){}.getType());
网友评论