Get the JSON object data for post in Request Content-type= "Text/plain"

Source: Internet
Author: User

in fact, the method used in http://www.cnblogs.com/SimonHu1993/p/7295750.html can be obtained,
is to get the JSON data by getting the stream data in the request, in theory the request data of various content-type should be applied.
/** * GET request in the Post method "Content-type" is * "Text/plain" sent JSON data  * @author: Simon * @date: August 6, 2017 pm 7:44:09 * @para M Request * @return * @throws ioexception */public static String Getpostbytextplain (HttpServletRequest request) throws IOE Xception{bufferedreader reader = Request.getreader ();        char[] buf = new char[512];        int len = 0;        StringBuffer contentbuffer = new StringBuffer ();        while (len = Reader.read (BUF))! =-1) {            contentbuffer.append (buf, 0, Len);        }        String content= contentbuffer.tostring ();        return content;}

  

Make a call in controll; String content = Httpjsonutils.getpostbytextplain (request);// Extracts the corresponding parameter values based on the object's key value and its type in the JSON data jsonobject jsobject = jsonobject.fromobject (content); try {usermob = jsobject.getstring (" Usermob "); cpid = jsobject.getstring (" cpid "); spid = jsobject.getstring (" spid "); type = jsobject.getstring (" type "); o Rdertime = jsobject.getstring ("Ordertime"); canceltime = jsobject.getstring ("Canceltime"); endtime = Jsobject.getstring ("Endtime"), Channelcode = jsobject.getstring ("Channelcode");p rovince = jsobject.getstring (" Province "), area = jsobject.getstring (" area "), OrderType = jsobject.getstring (" OrderType "); videoid = Jsobject.getstring ("VideoID");} catch (Exception e) {logger.info ("error occurred * * * * * * * *" + e.getmessage ());}

  

Get the JSON object data for post in Request Content-type= "Text/plain"

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.