Conversion between map and JSON

Source: Internet
Author: User

A map<string,object> is stored in the action in the session, and a jump to a.jsp,a.jsp is submitted to baction,baction via form to obtain the map value from the session.

But since the session is stored in Tomcat's memcached, storing large objects can affect the user's use, and if you put the map in request and pass through hidden, there is a problem passing the map between the pages.

So the idea of a solution is to convert the map to JSON, store it in the request, write hidden in a.jsp, and finally get the JSON in baction, and switch to map.

Map is converted to JSON in the following way:

Jsonobject jsonobject = Jsonobject.frommap (Productmap);  

Or

  Jsonobject jsonobject = Jsonobject.fromobject (Productmap);

  

The way JSON is converted to map is:

String json = Request.getprarameter ("Product");//Get JSON string from hidden

Objectmapper mapper = new Objectmapper ();  map<string,object> Productmap = Mapper.readvalue (JSON);//Turn into map  

  

Conversion between map and JSON

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.