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转化对特殊字段的处理的主要内容,如果未能解决你的问题,请参考以下文章

json格式如何读取有特殊字符的数据!内详!

Golang解析json的特殊情况处理

返回json时,字段为null的处理方式

C# .net中json字符串和对象之间的转化方法

后台拼接json字符串,传到前台时注意特殊符号处理

shell处理json串中带空格