.NET Core 3.0 已经使用了一整套内置的 Josn 序列化/反序列化方案,并且看上去效率还不错。但对于某些项目必须使用到 Newtonsoft.Json 的时候,就会抛出以下异常:spa
System.InvalidOperationException: Property 'JsonResult.SerializerSettings' must be an instance of type 'System.Text.Json.JsonSerializerOptions'.code
若是须要在 .NET Core 3.0 项目中支持 Newtonsoft.Json,只须要作两步:blog
一、引用 Nuget 包:https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.NewtonsoftJsonget
二、在 startup.cs 中,加入代码:it
public void ConfigureServices(IServiceCollection services) { services.AddControllersWithViews() //也能够是 AddMvc() 等其余扩展方法 .AddNewtonsoftJson(); // 支持 NewtonsoftJson //... }
三、完成。io