This is suitable for beginners: I just learned
1. Basic "JSON"
The object is with a pair of curly braces;
For example:
{
"name": "xiaohua",
"age": 23,
"susses": true
}
2. Array or List
Use a pair of brackets:
["a", "b", "c"]
3. Array of objects
[{"name": "userName", "age": +}]
The process used is heavy and can be verified using the Web site http://www.bejson.com/
for Example: There is a Person's class, age, name, wife, wife also has a name, has 2 children, the first child name, the second child name, The second child has a daughter, and the daughter also has a name Attribute.
{ "name": "pername", "age": $, "wife": { & nbsp; "wifename": "wifename" }, "son": [ { "son1": { "name": "son1" }, "son2": { "name": "son2" }, "dau": { "dauname": "dauname" } } ]}
3. Use the Idea tool for serialization and Deserialization.
Specific details of the wording you can do Baidu
public classjsontest {@Testpublic voidTestjson () {person person =NewPerson (); Person.setage ( -); Person.setname ("Lao Wang"); Wife Wife =NewWife (); Wife.setname ("Xiao Wang"); list<son> list =NewArrayList (); List List1 =NewLinkedList (); Son son =NewSon (); Son.setname (" daming"); Son Son1 =NewSon (); Son1.setname ("Xiao Ming"); Nver Nver =NewNver (); Nver.setname ("daughter"); Son1.setnver (nver); List.add (son); List.add (son1); Person.setwife (wife); Person.setsons (list); String JSON = Json.toJSONString (person, Serializerfeature.Writeclassname); System. out. println (json); Person Person1 = JSON.Parseobject (json, Person.class); list<son> sonlist = person1.getsons (); for(Son Son2:sonlist) {System. out. println (son2.getname ()); } System.out . println (); }} result: { "@type": "com.longteng.json.Person", "age": 18, "name" : "lao wang", "sons": [ { "@type": "com.longteng.json.Son", "name": "daming" }, { "@type": "com.longteng.json.Son" , "name": "xiao ming", "nver": { "name": "daughter" } } ], "wife": {&Nbsp; "name": "xiao wang" }}
Json's Simple Writing (beginner), using the Java language to deserialize