First Note: Note the Import and introduction of JAR packages.
Here is the code implementation:
1 ImportJava.util.HashMap;2 ImportJava.util.Map;3 ImportNet.sf.json.JSONObject;4 5 Public classTestjson {6 7 Public Static voidMain (string[] args) {8 testpingping ();9 }Ten //the tasks are all my friends, I hope they don't see ^_^ ^_^ ^_^ One Public Static voidtestpingping () { Amap<string, string> smallmap =NewHashmap<string, string>(); -Smallmap.put ("UserId", "438"); -Smallmap.put ("name", "Flat/ping"); theSmallmap.put ("Sex", "I don't know men and women"); -Smallmap.put ("Reason", "and studies to sleep one night, later studies mouth ache"); -Jsonobject Jsonobject =Jsonobject.fromobject (smallmap); -System.out.println ("The following are experts ' findings:"); + System.out.println (jsonobject); -SYSTEM.OUT.PRINTLN ("Patient identification completed!") "); +System.out.println ("Next"); A at } -}
Results of the output:
The following are experts ' findings:
{"B_name": "Flat/Ping Ping", "D_reason": "and studies to sleep one night, later studies mouth pain", "A_userid": "438", "c_sex": "I do not know men and women"}
Patient Identification Complete!
Next one
--------------------------------------------------------------------------------------------------
List of jar packages to be introduced:
Cglib-nodep-2.2.jar
Commons-beanutils-1.8.0.jar
Commons-collections-3.2.1.jar
Commons-lang-2.4.jar
Commons-logging-1.1.1.jar
Ezmorph-1.0.4.jar
Gson-2.8.0-javadoc.jar
Gson-2.8.0-sources.jar
Gson-2.8.0.jar
Jettison-1.3.1.jar
Json-lib-2.2.1-jdk13.jar
Json.jar
--------------------------------------------------------------------------------------------------
Ping elder brother ^_^ ha haha haha .....
Map<string,string> Converting JSON strings