JSON is often used for browser-to-server data transfer, so we often encapsulate and disassemble json in the browser and server segments, so here's a quick introduction to these.
1, the server side, that is, Java, we use Net.sf.json-lib, if it is maven, to add dependencies, with the following:
<!--json-lib--> <dependency> <groupId>net.sf.json-lib</groupId> < artifactid>json-lib</artifactid> <version>2.4</version> </dependency >
Pay special attention to the marked red part, must add, otherwise it will be wrong, because JSON has two versions, 13 and 15, where the choice of 15
The JSON is then parsed and encapsulated, with the first parsing
Json->list
Jsonarray Jsonarray = jsonarray.fromobject (jsonarraydata); List<Map<String,Object>> Maplistjson = (list) Jsonarray;
Json->map
Jsonobject jsonobject = jsonobject.fromobject (jsonobjectdata); Map<string, object> Mapjson = Jsonobject.fromobject (Jsonobject);
Json->object
/**@return*/privatestatic Object Json2simplebean () { = "{\" age\ ": 23,\" id\ ": 123,\" name\ ": \" Tt_2009\ "," + "\" province\ ": \" shanghai \ ", \" sex\ ": \" male \ "}"; = Jsonobject.fromobject (jsonstr); return Jsonobject.tobean (Jsonbean, Simpleuser. Class);}
Let's talk about wrapping it in a JSON style.
Next is jquery's encapsulation and parsing of JSON
1,str->Json$.parsejson (str); 2,json->strjson.stringify (obj)
Java,jquery parsing of JSON