1.响应内容(过滤前)

{"msg":"初始化成功!","code":"","success":true,data:null}

 

2.响应内容(过滤后)

{"msg":"初始化成功!","code":"","success":true}

    1. using System.Net.Http.Formatting;
    2. using System.Web.Http;
    3. namespace xxxxxxx
    4. {
    5. public static class WebApiConfig
    6. {
    7. public static void Register(HttpConfiguration config)
    8. {
    9. ......
    10. //默认返回 json
    11. GlobalConfiguration.Configuration.Formatters
    12. .JsonFormatter.MediaTypeMappings.Add(
    13. new QueryStringMapping("datatype", "json", "application/json"));
    14. //返回格式选择
    15. GlobalConfiguration.Configuration.Formatters
    16. .XmlFormatter.MediaTypeMappings.Add(
    17. new QueryStringMapping("datatype", "xml", "application/xml"));
    18. //json 序列化设置
    19. GlobalConfiguration.Configuration.Formatters
    20. .JsonFormatter.SerializerSettings = new Newtonsoft.Json.JsonSerializerSettings()
    21. {
    22. NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore //设置忽略值为 null 的属性
    23. };
    24. }
    25. }
    26. }

.net mvc web api 返回 json 内容时过滤值为null的属性的更多相关文章

  1. .net mvc web api 返回 json 内容,过滤值为null的属性

    原文:http://blog.csdn.net/xxj_jing/article/details/49508557 版权声明:本文为博主原创文章,未经博主允许不得转载. .net mvc web ap ...

  2. C# .net mvc web api 返回 json 内容,过滤值为null的属性

    在WebApiConfig.Register 中增加一段 #region 过滤值为null的属性 //json 序列化设置 GlobalConfiguration.Configuration.Form ...

  3. MVC web api 返回JSON的几种方式,Newtonsoft.Json序列化日期时间去T的几种方式。

    原文链接:https://www.muhanxue.com/essays/2015/01/8623699.html MVC web api 返回JSON的几种方式 1.在WebApiConfig的Re ...

  4. java对象json序列化时忽略值为null的属性

    环境: jdk: openjdk11 操作系统: windows 10教育版1903 目的: 如题,当一个对象里有些属性值为null 的不想参与json序列化时,可以添加如下注解 import com ...

  5. ASP.NET WEB API 返回JSON 出现2个双引号问题

    前言          在使用ASP.NET WEB API时,我想在某个方法返回JSON格式的数据,于是首先想到的就是手动构建JSON字符串,如:"{\"result\" ...

  6. .Net Web Api返回Json数据中原对象变量名大小写问题

    这两天在工作中使用SignalR的WebSocket做数据实时传递的功能开发,在后端主动向前端广播数据以Json传递时,前端获取的Json中对应类的变量名首字母默认传递的是大写.而前端一直获取到的后台 ...

  7. web Api 返回json 的两种方式

    web api写api接口时默认返回的是把你的对象序列化后以XML形式返回,那么怎样才能让其返回为json呢,下面就介绍两种方法: 方法一:(改配置法) 找到Global.asax文件,在Applic ...

  8. Web API返回JSON数据

    对Web API新手来说,不要忽略了ApiController 在web API中,方法的返回值如果是实体的话实际上是自动返回JSON数据的例如: 他的返回值就是这样的: { "Conten ...

  9. Web API 返回json文件的2中不用方式

    //方法一:直接返回序列化后的json文件 public static HttpResponseMessage ConvertToJson(this Object obj) { String str= ...

随机推荐

  1. git 不成功

    fatal: Interactive git shell is not enabled.hint: ~/git-shell-commands should exist and have read an ...

  2. Core Animation 文档翻译 (第五篇)

      构建Layer层次结构 在APP中大多数情况下,将Layer和View对象结合使用是Layer最好的使用方式.然而,很多时候我们可能需要通过添加单独的Layer对象,以便增加视图继承层次:当为了提 ...

  3. js万亿级数字转汉字的封装方法

    要求如图: 实现方法: function changeBillionToCN(c) { // 对传参进行类型处理,非字符串进行转换 if(typeof(c) != "string" ...

  4. AndroidStudio3更改包名失败

    使用Android Studio 3.0 Beta6更改包名refactor---rename一直提示:Refactoring cannot be performedFile xxx\build\xx ...

  5. 最大流模版 dinic

    朴素dinic+多路增广 #include <iostream> #include <cstdio> #include <cstring> #include < ...

  6. BZOJ 4566: [Haoi2016]找相同字符 [后缀自动机]

    4566: [Haoi2016]找相同字符 Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 275  Solved: 155[Submit][Statu ...

  7. http协议重点

    https://www.cnblogs.com/ranyonsue/p/5984001.html HTTP简介 HTTP协议是Hyper Text Transfer Protocol(超文本传输协议) ...

  8. 反反爬虫 IP代理

    0x01 前言 一般而言,抓取稍微正规一点的网站,都会有反爬虫的制约.反爬虫主要有以下几种方式: 通过UA判断.这是最低级的判断,一般反爬虫不会用这个做唯一判断,因为反反爬虫非常容易,直接随机UA即可 ...

  9. LNMP搭建01 -- 编译安装MySQL 5.6.14 和 LNMP相关的区别

    [编译安装MySQL 5.6.14] [http://www.cnblogs.com/xiongpq/p/3384681.html ]  [mysql-5.6.14.tar.gz 下载] http:/ ...

  10. Angular2 ^ 资源链接

     Angular2 资源链接 Material Desgin 2 githubhttps://github.com/Promact/md2 DEMOhttp://code.promactinfo.co ...