java json字符串转JSONObject对象、转JAVA对象、转List<T>对象

时间:2024-11-08 15:31:28
String jsonData = ""; //json格式的字符串

JSONObject jsonObj = (jsonData);//转JSONObject对象
String name = ("name").toString(); //取JSONObject对象中的数据
Student stu = (jsonData, ); //json字符串直接转给java对象
List<Student> list = (jsonData, ); //json字符串直接转为List<java>对象


List<Map<String, Object>> mapList = (List<Map<String, Object>>)(jsonData);

List<Map<String, Object>> mapList = (json, new TypeReference<List<Map<String, Object>>>() {
            })