码迷,mamicode.com
首页 > 编程语言 > 详细

Ajax调用返回json数组,对象 (JSONArray.fromObject)

时间:2014-11-06 12:36:38      阅读:278      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   io   color   ar   使用   sp   div   

   JSONArray和JSONObject的详细使用:http://blog.csdn.net/yangbobo1992/article/details/8350765
  /** * ajax调用返回json数组 * @param list */ public void printList(List<?> list){ HttpServletResponse response = ServletActionContext.getResponse(); //获取response实例 response.setContentType("text/html");      //设置输出类型 response.setCharacterEncoding("UTF-8"); //设置输出编码 /*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调用返回json对象 * @param obj */ public void printObject(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调用返回json对象 * @param obj */ public void printSting(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调用返回json数组,对象 (JSONArray.fromObject)

标签:style   blog   http   io   color   ar   使用   sp   div   

原文地址:http://www.cnblogs.com/hardwork/p/4078136.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!