JsonException: A possible object cycle was detected which is not supported. This can either be due to a cycle or if the object depth is larger than

后端 未结 6 925
执念已碎
执念已碎 2021-02-04 16:07

In my web api when i run project for get data from database got this error .net core 3.1

JsonException: A possible object cycle was detected which is not

6条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-04 16:25

    For net core 3.1 you have to add in Startup.cs:

    services.AddMvc.AddJsonOptions(o => {
    o.JsonSerializerOptions.ReferenceHandler = ReferenceHandler.Preserve;
    o.JsonSerializerOptions.MaxDepth = 0;
    })
    

    and import at least this package using nuget.org include prerelease:

    
    

提交回复
热议问题