I have previously written an article about gson's simple usage.ArticleToday, I want to write an article about how to explain JSON data without Google's gson.
We all know that before gson is available, Java will have JSON transmission and parsing. How does it complete ???
Before entering the topic, we now download some jar packages
These resources will be uploaded to my resource page soon. You are welcome to download them ....
Now let's create a Java project.
The object "person" contains only the string name and string age attributes and their set and get methods.
The key is the jsontest class.
First create a jsonobject object
Jsonobject JSON = new jsonobject ();
Create a person object
Person = newperson ("yang", "14 ");
Then use the following sentenceCodeConverts a Java object to a JSON object.
JSON = jsonobject. formobject (person );
To convert a JSON string to a Java object
You can use the following code
Jsonobject. tobean (JSON, person. Class );
So that the conversion between the JSON string and the Java object can be realized ~~ Heheh