zoukankan      html  css  js  c++  java
  • 使用json-org包实现POJO和json的转换

    使用json-org包实现POJO和json的转换

    这个jar包把对象转换成json超级舒服,所以顺便记录一下吧

    把单个pojo对象转换成json对象

            Student student = new Student("2015551404","熊大");
            JSONObject object = new JSONObject(student);
            System.out.println(object.toString(2));

    把多个pojo对象转成json数组

            Student student = new Student("2015551404","熊大");
            Student student1 = new Student("2015551405", "孙嘉宁");
            ArrayList<Student> list = new ArrayList<>();
            list.add(student);
            list.add(student1);
            JSONArray array = new JSONArray(list);
            System.out.println(array.toString(2));
  • 相关阅读:
    暴力,DFS,比较字符串
    暴力求解最大乘积
    油田!
    八皇后的问题
    巡逻的机器人
    骑士的移动
    二叉树遍历
    新兵训练(=@__@=)
    打牌~~~
    八皇后
  • 原文地址:https://www.cnblogs.com/xtuxiongda/p/9745738.html
Copyright © 2011-2022 走看看