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());
相關文章
相關標籤/搜索