JSON.NET Error Self referencing loop detected for type

后端 未结 25 2930
我在风中等你
我在风中等你 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:30

    To ignore loop references and not to serialize them globally in MVC 6 use the following in startup.cs:

        public void ConfigureServices(IServiceCollection services)
        {
            services.AddMvc().Configure(options =>
            {
                options.OutputFormatters.RemoveTypesOf();
                var jsonOutputFormatter = new JsonOutputFormatter();
                jsonOutputFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
                options.OutputFormatters.Insert(0, jsonOutputFormatter);
            });
        }
    

提交回复
热议问题