从API返回结果列表时出现异常错误 [英] Unusual error when returning list of results from API

查看:125
本文介绍了从API返回结果列表时出现异常错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在从.NET Core 3.X API返回数据,但始终收到此奇怪的错误:

I'm returning data from a .NET Core 3.X API but keep getting this strange error:

System.Text.Json.JsonException:检测到不支持的可能的对象循环.这可能是由于循环造成的,或者是由于对象深度大于允许的最大深度32而引起的.

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

我希望数据能正常返回,而不是500错误

I expect the data to return normally rather than a 500 error

推荐答案

您的ClientCarer都通过ClientCarer相互间接引用.

Your Client and Carer both have indirect references to each other via ClientCarer.

我建议不要只用您需要的特定属性来创建新的类/匿名类型,而不要使用ClientCarer.

Rather than serving Client and Carer up I'd suggest creating a new class / anonymous type with just the specific properties you need.

这篇关于从API返回结果列表时出现异常错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆