How to use Newtonsoft.Json as default in Asp.net Core Web Api?

后端 未结 3 1420
予麋鹿
予麋鹿 2020-11-30 07:19

I am new to ASP.Net Web Api Core. I have been using ASP.Net MVC for past few years and I always have written an ActionFilter a

3条回答
  •  孤城傲影
    2020-11-30 08:09

    here is a code snippet to adjust the settings for a .net core application

    public void ConfigureServices(IServiceCollection services)
    {
        services
            .AddMvc()
            .AddJsonOptions(options => {
                // send back a ISO date
                var settings = options.SerializerSettings;
                settings.DateFormatHandling = Newtonsoft.Json.DateFormatHandling.IsoDateFormat;
                // dont mess with case of properties
                var resolver = options.SerializerSettings.ContractResolver as DefaultContractResolver;
                resolver.NamingStrategy = null;
            });
    }
    

提交回复
热议问题