JSONobject转化对象,数组

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);
发布了27 篇原创文章 · 获赞 1 · 访问量 841

猜你喜欢

转载自blog.csdn.net/weixin_44971379/article/details/105084152