Fastjson JSON string goto list and map

Source: Internet
Author: User
Tags goto

Fastjson is Ali produced JSON processing plug-ins, relatively lightweight, easy-to-use, many domestic companies are used in production systems. For a better user experience, a typical Web application uses AJAX techniques in the page, asynchronously loading data, or submitting data. The format for data transmission between the Web front-end and the server is mostly in JSON format, so processing JSON becomes a basic development technique during application development.

Common JSON processing grooming:

1. Parse the data sent by the Web front-end request and convert the JSON data to the map object:

map<string, object> param = requestutil.getmapobjbyrequest (); 

/* param content is:
{page.start=0
, aeras=[
{"passstation": "001001001,001001008", "StartTime": "2016-10-16 00:00:00 "," Endtime ":" 2016-10-16 23:59:59 "}
, {" passstation ":" 001001001,001001008 "," StartTime ":" 2016-10-17 00:00:00 "," Endtime ":" 2016-10-17 23:59:59 "}
, {" passstation ":" 001001001,001001008 "," StartTime ":" 2016-10-18 00:00:00 "," Endtime ":" 2016-10-18 23:59:59 "}
, {" passstation ":" 001001001,001001008 "," StartTime ":" 2016-10-19 00:00:00 "," Endtime ":" 2016-10-19 23:59:59 "}
, {" passstation ":" 001001001,001001008 "," StartTime ":" 2016-10-20 00:00:00 "," Endtime ":" 2016-10-20 23:59:59 "}
], endnum=5, page.limit=25, startnum=3}
* * *
2, remove the properties of the object--key-value:

/* Remove Startnum attribute */
int startnum = Integer.parseint (Param.get ("Startnum"). toString ());
3. Convert a JSON string array to list:
list<object> list = Jsonarray
                . Parsearray (Param.get ("Aeras"). ToString (), object.class);
4, Traverse list:

for (Object obj:list) {
     map<string, object> item = (map<string, object>) obj;
     System.out.println (Item.get ("Passstationone"));
}



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.