首页 > 其他分享 >.Net Core 3.0 possible object cycle was detected which is not supported

.Net Core 3.0 possible object cycle was detected which is not supported

时间:2022-11-09 13:00:10浏览次数:69  
标签:Core object ReferenceHandler supported JsonSerializerOptions Net options

.Net Core 3.0 possible object cycle was detected which is not supported

 

回答1

Instead of using NewtonsoftJson I used System.Text.Json.Serialization

For .Net Core 3.1

In Startup.cs

 public void ConfigureServices(IServiceCollection services)
 {
    ..........
    .......

    services.AddControllers().AddJsonOptions(options =>
    {
        options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
        options.JsonSerializerOptions.WriteIndented = true;
    });
 }

For .Net 6

In Program.cs

builder.Services.AddControllers().AddJsonOptions(options => 
{ 
    options.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.IgnoreCycles;
    options.JsonSerializerOptions.WriteIndented = true;
});

 

标签:Core,object,ReferenceHandler,supported,JsonSerializerOptions,Net,options
From: https://www.cnblogs.com/chucklu/p/16873262.html

相关文章