ASP.NET Core 3.1 默认移除了 Newtonsoft.Json ,使用了微软自己实现的 System.Text.Json,如果要改为 Newtonsoft.Json ,需要以下2步
1.安装Nuget包:
Install-Package Microsoft.AspNetCore.Mvc.NewtonsoftJson
2.注册
services.AddControllers().AddNewtonsoftJson();
注:如果要使用JsonProperty设置属性的输出名要按以上2个步骤才有效
public class WeatherForecast
{
public DateTime Date { get; set; }
[JsonProperty("temp")]
public int TemperatureC { get; set; }
}