JSON.NET Error Self referencing loop detected for type

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

    Team:

    This works with ASP.NET Core; The challenge to the above is how you 'set the setting to ignore'. Depending on how you setup your application it can be quite challenging. Here is what worked for me.

    This can be placed in your public void ConfigureServices(IServiceCollection services) section.

    services.AddMvc().AddJsonOptions(opt => 
            { 
          opt.SerializerSettings.ReferenceLoopHandling =
          Newtonsoft.Json.ReferenceLoopHandling.Ignore;
            });
    

提交回复
热议问题