JSONObject:将Bean对象转化为JSON数据

导入的包:java

commons-beanutils-1.8.3.jar
commons-collections-3.2.1.jar
commons-lang-2.5.jar
commons-logging-1.1.1.jar
ezmorph-1.0.6.jar
json-lib-2.4-jdk15.jar
xom-1.1.jarjson

JSONObject.fromObject(Bean).toString():将Bean对象转化为String类型的JSON数据code

JSONArray.fromObject(List<Bean>).toString():将Bean的List列表转化为String类型的JSON数据对象

JSONArray还能够这么使用:ci

        City city1=new City("张三","dsda1");
        City city2=new City("李四","我是李四");
        JSONArray jsonArray=new JSONArray();
        jsonArray.add(city1);
        jsonArray.add(city2);
        System.out.println(jsonArray.toString());
相关文章
相关标签/搜索