Suppress properties with null value on ASP.NET Web API

前端 未结 5 1991
清歌不尽
清歌不尽 2020-11-28 05:18

I\'ve created an ASP.Net WEB API Project that will be used by a mobile application. I need the response json to omit null properties instead of return them as property

5条回答
  •  日久生厌
    2020-11-28 05:54

    I ended up with this piece of code in the startup.cs file using ASP.NET5 1.0.0-beta7

    services.AddMvc().AddJsonOptions(options =>
    {
        options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
    });
    

提交回复
热议问题