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"));
}