Fastjson of Jsonobject and Jsonarray

Source: Internet
Author: User

Jsonobject,jsonarray is the two subclass of JSON.

First we look at jsonobject Source:

You will find that Jsonobject is inherited map<string, Object>, and are all methods used in map. Can say jsonobject equivalent to map<string, object>

Take a look at the concrete examples:

/ ** * Turn map into jsonobject, then add element, output*/@Test Public voidTestjsonobject () {Map<string, object> TestMap =NewHashmap<>(); Testmap.put ("Key1","value1"); Testmap.put ("Key2","value2"); Jsonobject Jsonobj=NewJsonobject (TestMap); Jsonobj.put ("Key3","Value3"); System. out. println (Jsonobj); System. out. println (Jsonobj.Get("Key2")); }

Operation Result:

{"key1":"value1","key2":"  value2","key3":"value3"  }value2

Look at the source of Jsonarray:

You will find that Jsonarray is an inherited list<object>, and are all methods used in the list. Can say jsonarray equivalent to list<object>

Specific examples:

/ ** * Convert List object to Jsonarray, then output*/@Test Public voidTestjsonarray () {List<Object> list =NewArraylist<>(); List.add ("Home"); List.add ( -); List.add (true); List.add (NewXwjuser (1,"Hello World",NewDate ())); Jsonarray Jsonarr=Jsonarray.parsearray (json.tojsonstring (list)); System. out. println (Jsonarr); }

Operation Result:

["home",max,true, {"ID":1,"  message":HelloWorld", "sendtime  ":1525237337937}]

Fastjson of Jsonobject and Jsonarray

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.