Ajax calls return JSON array, object (Jsonarray.fromobject)

Source: Internet
Author: User

Details of Jsonarray and Jsonobject use: http://blog.csdn.net/yangbobo1992/article/details/8350765
   /** * Ajax call returns JSON array * @param list*/ Public voidPrintlist (list<?>list) {HttpServletResponse response=Servletactioncontext.getresponse (); Gets the response instance Response.setcontenttype ("text/html"); Set the output type response.setcharacterencoding ("UTF-8"); Set Output Encoding/*jsonconfigfactory.getinstance (); Jsonarray Jsonarray = new Jsonarray (); Jsonarray.addall (list, jsonconfigfactory.getinstance ()); */ Try{response.getwriter (). Print (Jsonarray.fromobject (list, jsonconfigfactory.getinstance ())); } Catch(IOException e) {e.printstacktrace (); } } /** * Ajax Call returns JSON object * @param obj*/ Public voidprintobject (Object obj) {httpservletresponse response=Servletactioncontext.getresponse (); Response.setcontenttype ("text/html"); Response.setcharacterencoding ("UTF-8"); Try{response.getwriter (). Print (Jsonobject.fromobject (obj,jsonconfigfactory.getinstance ())); } Catch(IOException e) {e.printstacktrace (); } } /** * Ajax Call returns JSON object * @param obj*/ Public voidprintsting (String str) {httpservletresponse response=Servletactioncontext.getresponse (); Response.setcontenttype ("text/html"); Response.setcharacterencoding ("UTF-8"); Try{response.getwriter (). print (str); } Catch(IOException e) {E.printstacktrace (); }

Ajax calls return JSON array, object (Jsonarray.fromobject)

Related Article

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.