JSON.NET Error Self referencing loop detected for type

后端 未结 25 3503
我在风中等你
我在风中等你 2020-11-22 02:16

I tried to serialize POCO class that was automatically generated from Entity Data Model .edmx and when I used

JsonConvert.SerializeObject 

25条回答
  •  佛祖请我去吃肉
    2020-11-22 02:24

    In .NET Core 1.0, you can set this as a global setting in your Startup.cs file:

    using System.Buffers;
    using Microsoft.AspNetCore.Mvc.Formatters;
    using Newtonsoft.Json;
    
    // beginning of Startup class
    
        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc(options =>
            {
                options.OutputFormatters.Clear();
                options.OutputFormatters.Add(new JsonOutputFormatter(new JsonSerializerSettings(){
                    ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                }, ArrayPool.Shared));
            });
        }
    

提交回复
热议问题