zl程序教程

您现在的位置是:首页 >  后端

当前栏目

java方法返回json数据详解编程语言

2023-06-13 09:20:41 时间
@RequestMapping("/returnjson") public void returnjson(HttpServletRequest request,HttpServletResponse response, HttpSession session) { response.setCharacterEncoding("UTF-8"); response.setContentType("text/html;charset=UTF-8"); PrintWriter wirte = null; JSONObject json = new JSONObject(); try { wirte = response.getWriter(); if(1==1){ json.put("等式成立", "yes"); }else{ json.put("等式不成立", "no"); } catch (Exception e) { log.error(e, e); }finally{ wirte.print(json); wirte.flush(); wirte.close(); }

二:启动项目访问:http://localhost:8080/wx/returnjson.do

三:结果

{ 等式成立 : yes }

13980.html

cjava