旧版asp的json序列化程序设置.net核心应用程序是通过增加AddMvc().AddJsonOptions()
来设置的,但我没有在asp.net core 3
中使用AddMvc()
.那么如何设置全局json序列化设置呢?
旧版asp的json序列化程序设置.net核心应用程序是通过增加AddMvc().AddJsonOptions()
来设置的,但我没有在asp.net core 3
中使用AddMvc()
.那么如何设置全局json序列化设置呢?
AddMvc
returns an IMvcBuilder
implementation, which has a corresponding AddJsonOptions
extension method. The new-style methods AddControllers
, AddControllersWithViews
, and AddRazorPages
also return an IMvcBuilder
implementation. Chain with these in the same way you would chain with AddMvc
:
services.AddControllers()
.AddJsonOptions(options =>
{
// ...
});
Note that options
here is no longer for Json.NET, but for the newer System.Text.Json
APIs. If you still want to use Json.NET, see tymtam's answer