Json's Simple Writing (beginner), using the Java language to deserialize

Source: Internet
Author: User
Tags ming

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.