欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

JSON转换实体类

程序员文章站 2022-06-15 12:02:16
...
String stu = {
    "employees": [{"firstName": "Bill","lastName": "Gates"},
    {"firstName":"George","lastName":"Bush"},
    {"firstName": "Thomas","lastName": "Carter"}]}
JSONObject jsonObject = JSONObject.fromObject(stu);
Bean stu1 = (Bean) JSONObject.toBean(jsonObject, Bean.class);

JSONObject jsonObject2 = JSONObject.fromObject(stu1.getEmployees.get(0));
Bean1 stu2 = (Bean1) JSONObject.toBean(jsonObject2, Bean1.class);

相关标签: json json