问题描述
我正在从.NET Core 3.x API返回数据,但请继续遇到这个奇怪的错误:
system.text.json.jsonexception:检测到不支持的对象周期.这可能是由于一个周期引起的,或者如果对象深度大于最大允许的深度32.
.
这是我在使用数据后立即将数据返回的内容.
var bookings = bookingData .Select(x => new SpecialTaskVm(new TaskViewModel(x, null)) { client = x.Client, carer = x.Carer, carer2 = x.Carer2 }) .ToList();
我尝试更改控制器方法类型
我希望数据正常返回,而不是500错误
推荐答案
您的Client和Carer都通过ClientCarer.
互相间接引用而不是服务Client和Carer up,我建议创建一个新的类/匿名类型,仅具有所需的特定属性.
问题描述
I'm returning data from a .NET Core 3.X API but keep getting this strange error:
System.Text.Json.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 the maximum allowed depth of 32.
Here is what I'm doing with the data before immediately returning it after.
var bookings = bookingData .Select(x => new SpecialTaskVm(new TaskViewModel(x, null)) { client = x.Client, carer = x.Carer, carer2 = x.Carer2 }) .ToList();
I have tried changing the controller method type
I expect the data to return normally rather than a 500 error
推荐答案
Your Client and Carer both have indirect references to each other via ClientCarer.
Rather than serving Client and Carer up I'd suggest creating a new class / anonymous type with just the specific properties you need.