Suppress properties with null value on ASP.NET Web API

前端 未结 5 1983
清歌不尽
清歌不尽 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:37

    For ASP.NET Core 3.0, the ConfigureServices() method in Startup.cs code should contain:

    services.AddControllers()
        .AddJsonOptions(options =>
        {
            options.JsonSerializerOptions.IgnoreNullValues = true;
        });
    

提交回复
热议问题