Chinaunix首页 | 论坛 | 博客
  • 博客访问: 3259385
  • 博文数量: 286
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 2109
  • 用 户 组: 普通用户
  • 注册时间: 2019-10-28 13:40
文章分类

全部博文(286)

文章存档

2022年(59)

2021年(155)

2020年(50)

2019年(22)

我的朋友

分类: Java

2021-07-15 17:17:41

public class Test1 {

    public static void main(String[] args) {

      /*  JSONObject jsonObject = new JSONObject();

        jsonObject.put("name", "aaa");

        jsonObject.put("code", "123");

        TestBean testBean = JSONObject.toJavaObject(jsonObject, TestBean.class);

        System.out.println(testBean);*/

        JSONObject jsonObject = new JSONObject();

        jsonObject.put("name", "aaa");

        jsonObject.put("code", "123");

        JSONObject a = new JSONObject();

        a.put("id", 1);

        a.put("name", "属性a");

        JSONArray array = new JSONArray();

        array.add(a);

        jsonObject.put("listBean", array);

        TestBean testBean = JSONObject.toJavaObject(jsonObject, TestBean.class);

        System.out.println(testBean);

    }

}

class TestBean {

    private String name;

    private String code;

    List listBean;

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }

    public String getCode() {

        return code;

    }

    public void setCode(String code) {

        this.code = code;

    }

    public List getListBean() {

        return listBean;

    }

    public void setListBean(List listBean) {

        this.listBean = listBean;

    }

    @Override

    public String toString() {

        return "TestBean{" +

                "name='" + name + '\'' +

                ", code='" + code + '\'' +

                ", listBean=" + listBean +

                '}';

    }

}

class A {

    private Integer id;

    private String name;

    public Integer getId() {

        return id;

    }

    public void setId(Integer id) {

        this.id = id;

    }

    public String getName() {

        return name;

    }

    public void setName(String name) {

        this.name = name;

    }

    @Override

    public String toString() {

        return "A{" +

                "id=" + id +

                ", name='" + name + '\'' +

                '}';

    }

}

阅读(1057) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~