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));
  • 相关阅读:
    OSX中zsh新增环境变量
    新的开始 春光明媚
    tmux
    继承
    6
    Object类
    网页收藏
    画王八
    ES6 语法之import export
    ES6 语法 之 destructuring
  • 原文地址:https://www.cnblogs.com/xtuxiongda/p/9745738.html
Copyright © 2011-2022 走看看