【发布时间】:2021-06-30 04:08:29
【问题描述】:
尝试设置全新的 .Net 5.0 API 并运行服务,但我想使用 NodaTime,但我不知道如何让序列化设置正常工作。以下似乎是正确的,但得到,
The JSON value could not be converted to NodaTime.LocalDate
尝试发送时
{
"date": "2021-Jan-01"
}
这是我当前的配置:
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NodaTime;
using NodaTime.Serialization.JsonNet;
namespace src
{
public class Startup
{
public void ConfigureServices(IServiceCollection services)
{
services
.AddControllers()
.AddJsonOptions(_ =>
{
new JsonSerializer()
.ConfigureForNodaTime(DateTimeZoneProviders.Tzdb);
});
}
【问题讨论】:
标签: c# .net-core asp.net-core-webapi nodatime