JSONObject与JSONArray使用
JSONObject与JSONArray Java 不像 PHP 解析和生产JSON总是一个比较痛苦的过程。但是使用JSONObject和JSONArray会让整个过程相对舒服一些。 JsonObject和JsonArray区别就是JsonObject是对象形式,JsonArray是数组形式 需要依赖的包: commons-lang.jar commons-beanutils.jar commons-collections.jar commons-logging.jar ezmorph.jar json-lib-2.2.2-jdk15.jar 生成JSON: [java] view plain copy print ? public class Test2 { public static void main(String[] args) { /* 创建JsonObject第一种方法 */ JSONObject jsonObject = new JSONObject(); jsonObject.put("UserName", "ZHULI"); jsonObject.put("age", "30"); jsonObject.put("workIn", "ALI"); System.out.println("jsonObject1:" + jsonObject); /*