![](/img/trans.png)
[英]Using new Json serializer with HttpContext.Response in ASP.NET Core 3.1
[英]How to setup nodatime json serializer in asp.net core 3.1
我试图弄清楚如何在 ASP.NET Core 3.1 Web Api 项目中设置 NodaTime JSON 序列化。 这里描述的方式对我不起作用
services.AddJsonFormatters(settings => settings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb));
因为在services : IServiceCollection
上没有像AddJsonFormatters
这样的方法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
你能帮我解决这个问题吗? 我应该在 Startup.cs 中使用什么方法来配置 NodaTime?
我正在寻找具有所需扩展方法ConfigureForNodaTime()
的JsonSerializerSettings
类,并在MvcNewtonsoftJsonOptions
SerializerSettings
字段中找到它并将其配置如下:
services.AddControllers().AddNewtonsoftJson(s =>
s.SerializerSettings.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb));
添加 Nuget 包“NodaTime.Serialization.SystemTextJson”
然后执行以下操作
using NodaTime.Serialization.SystemTextJson;
....
.AddJsonOptions(options =>
{
options.JsonSerializerOptions.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.