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)