使用json必须的包
commons-logging-1.0.4.jar commons-lang-2.3.jar commons-collections-3.2.jar commons-beanutils-1.7.0.jar json-lib-2.2.1-jdk15.jar ezmorph-1.0.4.jar
List list = new ArrayList();list.add( "first" );list.add( "second" );JSONArray jsonArray2 = JSONArray.fromObject( list );
Map map = new HashMap();map.put("name", "json");map.put("bool", Boolean.TRUE);map.put("int", new Integer(1));map.put("arr", new String[] { "a", "b" });map.put("func", "function(i){ return this.arr[i]; }");JSONObject json = JSONObject.fromObject(map);
JSONObject jsonObject = JSONObject.fromObject(new JsonBean());
boolean[] boolArray = new boolean[] { true, false, true };JSONArray jsonArray1 = JSONArray.fromObject(boolArray);
JSONArray jsonArray3 = JSONArray.fromObject("['json','is','easy']" );
List list = new ArrayList();JsonBean2 jb1 = new JsonBean2();jb1.setCol(1);jb1.setRow(1);jb1.setValue("xx");JsonBean2 jb2 = new JsonBean2();jb2.setCol(2);jb2.setRow(2);jb2.setValue("");list.add(jb1);list.add(jb2);JSONArray ja = JSONArray.fromObject(list);