1:json字符串转换为实体类(字符串可包含多于实体类的属性值)
{"name": "rt5",
"email": "[email protected]",
"address": "chaoyang",
"sex": "男",
"age": 66,
"aa":"aa",
"bb":"bb",
"cc":"cc"}
实体类
student(表):
id
name
age
email
address
SEX
crt_time
upd_time
转化:
T parseObject(String text, Class<T> clazz)
Student student = JSONObject.parseObject(jsonStr, Student.class);
2:字符成数组的转换
[{"name": "rt5",
"email": "[email protected]",
"address": "chaoyang",
"sex": "男",
"age": 66,
"aa":"aa",
"bb":"bb",
"cc":"cc"},{"name": "rt5",
"email": "[email protected]",
"address": "chaoyang",
"sex": "男",
"age": 66,
"aa":"aa",
"bb":"bb",
"cc":"cc"}]
转化:
List<T> parseArray(String text, Class<T> clazz)
List<Student> list = JSONArray.parseArray(jsonStr, Student.class);