json lib包 下载
1、List
Java代码
boolean[] boolArray =newboolean[];
JSONArray jsonArray1 = JSONArray.fromObject( boolArray );
System.out.println( jsonArray1 );
// prints [true,false,true]
List list =newArrayList();
list.add("first");
list.add("second");
JSONArray jsonArray2 = JSONArray.fromObject( list );
System.out.println( jsonArray2 );
// prints ["first","second"]
JSONArray jsonArray3 = JSONArray.fromObject("['json','is','easy']");
System.out.println( jsonArray3 );
// prints ["json","is","easy"]
2、Map
Java代码
Map map =newHashMap();
map.put("name","json");
map.put("bool", Boolean.TRUE );
map.put("int",newInteger(1) );
map.put("arr",newString[] );
map.put("func","function(i)");
JSONObject json = JSONObject.fromObject( map );
System.out.println( json );
//{"func":function(i),"arr":["a","b"],"int":1,"name":"json","bool":true}
3、BEAN
Java代码
/**
* Bean.java
private String name = "json";
private int pojoId = 1;
private char[] ptions = new char[];
private String func1 = "function(i)";
private JSONFunction func2 = new JSONFunction(new String[],"return this.options[i];");
*/
JSONObject jsonObject = JSONObject.fromObject(newJsonBean() );
System.out.println( jsonObject );
//{"func1":function(i),"pojoId":1,"name":"json","options":["a","f"],"func2":function(i)}
4、BEANS
Java代码
/**
&n