json转化对特殊字段的处理
Posted kisstear
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了json转化对特殊字段的处理相关的知识,希望对你有一定的参考价值。
//获取部门id String departmentId = (String)this.getRequest().getParameter("departmentId"); //根据部门id查询用户list List<Admin> adminList = adminService.findAllListBydepartment(departmentId); try { JsonConfig jsonConfig = new JsonConfig(); //建立配置文件 jsonConfig.setIgnoreDefaultExcludes(false); //设置默认忽略 jsonConfig.setExcludes(new String[]{"roles"}); //此处是亮点,只要将所需忽略字段加到数组中即可 HttpServletResponse response = this.getResponse(); response.setContentType("text/plain;charset=UTF-8"); JSONArray array = JSONArray.fromObject(adminList, jsonConfig); response.getWriter().print(array); } catch (Exception e) { e.printStackTrace(); }
以上是关于json转化对特殊字段的处理的主要内容,如果未能解决你的问题,请参考以下文章