那一夜....
风在刮,雨在下
   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(); }
posted on 2014-11-06 10:43  暮雨倾晨  阅读(5248)  评论(0编辑  收藏  举报