Http://www.jb51.net/article/90914.htm
In the development process, often need to exchange data with other systems, the format of data exchange is XML, JSON, etc., JSON as a lightweight data format than XML efficiency, XML needs a lot of tags, which undoubtedly occupy the network traffic, JSON is doing well in this respect, Let's look at the JSON format below,
JSON can be in two formats, one in object format and the other as an array object.
{"Name": "JSON", "Address": "Xicheng District, Beijing", "age": 25}//json Object-formatted string
[{"Name": "JSON", "Address": "Xicheng District, Beijing", "age": 25}]//data Object Format
From the above two formats can be seen in the object format and the format of the array object is the only difference is the object format based on the addition of [], and then to see the specific structure, you can see the form of key-value pairs, the middle of the English state of the comma (,) separated.
This format is also popular when transmitting data at the front and back ends, and the backend returns a JSON-formatted string, and the foreground uses the Json.parse () method in JS to parse the JSON string into a JSON object and then traverse it for use by the front end.
Let's go to the bottom and introduce the interaction between JSON and Java objects in Java.
To implement the interaction between JSON and Java objects, you need a third-party jar package, which uses the Json-lib jar package: https://sourceforge.net/projects/json-lib/, Json-lib need Commons-beanutils-1.8.0.jar, Commons-collections-3.2.1.jar, Commons-lang-2.5.jar, Commons-logging-1.1.1.jar, Ezmorph-1.0.6.jar Five packs of support, you can download from the Internet, no longer posted here.
Json-lib provides several classes that can accomplish this function, for example, Jsonobject, Jsonarray. From the name of the class you can see that the Jsonobject transformation should be the object format, while the Jsonarray conversion should be the array object (i.e., with [] form).
One, Java common Object and JSON string of the mutual transfer
Java Object--"string"
Java generic object refers to a Java Bean in Java, that is, an entity class, such as,
An example of an interchange of JSON strings and Java objects in Java (GO)