JSON objects and Java object transformations

Source: Internet
Author: User
Tags object object

Recommended Sites:

Http://www.runoob.com/json/json-stringify.html

Http://www.w3school.com.cn/json/json_eval.asp

Transferred from: http://www.jb51.net/article/120737.htm

First, the introduction of the Json-lib package

1. The JSON string is converted to a list object:

Jsonarray Jsonarray = Jsonarray.fromobject (jsonstring); list<config> list = (list) jsonarray.tocollection (Jsonarray,class.class);

2. JSON string converted to object

Jsonobject jsonobject = Jsonobject.fromobject (jsonstring); Object object = (object) Jsonobject.tobean (Jsonobject, Object.class);

3. The JSON string is converted to an object containing the list object

Jsonobject jsonobject = Jsonobject.fromobject (jsonstring); map<string, class> listmap = new hashmap<string, class> (); Listmap.put ("list", Listobject.class);
Object object = (object) Jsonobject.tobean (Jsonobject, Object.class, Listmap);

The Ps:object object may contain multiple objects, and the object may contain multiple list objects nested within each other.
Simply assemble all the list object values into a Map object, and the corresponding key will be the name of the list object's property.

JSON objects and Java object transformations

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.