JSON.Net Self referencing loop detected

前端 未结 11 867
伪装坚强ぢ
伪装坚强ぢ 2020-11-28 04:18

I have a mssql database for my website within 4 tables.

When I use this:

public static string GetAllEventsForJSON()
{
    using (CyberDBDataContext d         


        
11条回答
  •  余生分开走
    2020-11-28 05:09

    I am using Dot.Net Core 3.1 and did an search for

    "Newtonsoft.Json.JsonSerializationException: Self referencing loop detected for property "

    I am adding this to this question, as it will be an easy reference. You should use the following in the Startup.cs file:

     services.AddControllers()
                    .AddNewtonsoftJson(options =>
                    {
                        // Use the default property (Pascal) casing
                        options.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                        options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                    });
    

提交回复
热议问题