报错信息
An unhandled exception occurred while processing the request.
JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than the maximum allowed depth of 32.
System.Text.Json.ThrowHelper.ThrowInvalidOperationException_SerializerCycleDetected(int maxDepth)
解决方案
1、安装包Microsoft.AspNetCore.Mvc.NewtonsoftJson
2、在Startup.cs中添加如下代码
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
services.AddMvcCore().AddNewtonsoftJson(options => {
options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
});
services.AddControllers();
}