JSON's conversion to Java data (JSON, the JavaScript Object natation) is a lightweight data interchange format that is ideal for server interaction with JavaScript. )
The code has this sentence, is the background of the encapsulation data. Jsonobject Jo = jsonobject.fromobject (map);
Common Java code converted to JSON
--Please note that this method has caused me confusion. Because it is converted to object by all GetXXX () methods in the domain class. If you write a getxxx () method in a class, you will have the XXX attribute returned to you.
--Use the class under net.sf.json.* (Jar package is Json-lib-x.x.jar)
1. List collection converted to JSON code
List List = new ArrayList ();
List.add ("a");
List.add ("second");
Jsonarray jsonArray2 = jsonarray.fromobject (list);
2. Map collection converted to JSON code
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);
3. Bean converted to JSON code
Jsonobject jsonobject = jsonobject.fromobject (New Jsonbean ());
4. Convert array into JSON code
boolean[] Boolarray = new boolean[] {true, false, true};
Jsonarray jsonArray1 = Jsonarray.fromobject (Boolarray);
5. Convert general data into JSON code
Jsonarray jsonArray3 = Jsonarray.fromobject ("[' json ', ' is ', ' easy ']");