如何在 asp.net core 3.1 中设置 nodatime json 序列化程序

Vit*_*nko 0 c# nodatime asp.net-core-3.1

我试图弄清楚如何在 ASP.NET Core 3.1 Web Api 项目中设置 NodaTime JSON 序列化。这里描述的方式对我不起作用

services.AddJsonFormatters(settings => settings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb));
Run Code Online (Sandbox Code Playgroud)

因为没有像AddJsonFormatterson这样的方法services : IServiceCollection
安装的软件包:

NodaTime v 3.0.3  
NodaTime.Serialization.JsonNet v 3.0.0
Microsoft.AspNetCore.Mvc.NewtonsoftJson v 3.1.9
Newtonsoft.Json v 12.0.3
Run Code Online (Sandbox Code Playgroud)

你能帮我解决这个问题吗?我应该在 Startup.cs 中使用什么方法来配置 NodaTime?

Vit*_*nko 5

我正在寻找JsonSerializerSettings具有所需扩展方法的类,ConfigureForNodaTime()并在SerializerSettings字段中找到它MvcNewtonsoftJsonOptions并将其配置如下:

services.AddControllers().AddNewtonsoftJson(s =>
    s.SerializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb));
Run Code Online (Sandbox Code Playgroud)