导入的包:
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.jar
JSONObject.fromObject(Bean).toString():将Bean对象转化为String类型的JSON数据
JSONArray.fromObject(List<Bean>).toString():将Bean的List列表转化为String类型的JSON数据
JSONArray还可以这么使用:
City city1=new City("张三","dsda1");
City city2=new City("李四","我是李四");
JSONArray jsonArray=new JSONArray();
jsonArray.add(city1);
jsonArray.add(city2);
System.out.println(jsonArray.toString());