It's easy to convert Java standard data structures ArrayList and HashMap to JSON objects and arrays
Only jsonarray.fromobject (obj) is required, or jsonobject.fromobject (obj);
Convert a JSON object to a map (must use traversal)
Public Static voidMain (string[] args) {HashMap<string, object> map =NewHashmap<string, object>(); Map.put ("Name", "Tom"); Map.put ("Age", 12); Jsonobject obj=jsonobject.fromobject (map); System.out.println (obj);//{"name": "Tom", "Age":HashMap<string, object> map1=NewHashmap<string, object>(); Iterator it=Obj.keys (); while(It.hasnext ()) {String key=(String) it.next (); Object value=Obj.get (key); Map1.put (key, value); } System.out.println (MAP1);//{name=tom, age=12}System.out.println (Jsonobject.fromobject (MAP1));//{"name": "Tom", "Age":}
Public Static voidMain (string[] args) {ArrayList<String> list =NewArraylist<string>(); List.add ("Tom"); List.add ("Lisa"); SYSTEM.OUT.PRINTLN (list);//[Tom, Lisa]Jsonarray array =jsonarray.fromobject (list); SYSTEM.OUT.PRINTLN (array);//["Tom", "Lisa"]ArrayList<String> List1 =NewArraylist<string>(); Iterator<String> it =List.iterator (); while(It.hasnext ()) {List1.add (It.next ()); } System.out.println (List1);//[Tom, Lisa]}
(essence) converts JSON arrays and objects into lists and maps (dialogue between dragons and New)