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 1035
执念已碎
执念已碎 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:27

    Finally fixed mine with System.Text.Json not NewtonSoft.Json using

    var options = new JsonSerializerOptions()
            {
                MaxDepth = 0,
                IgnoreNullValues = true,
                IgnoreReadOnlyProperties = true
            };
    

    Using options to serialize

    objstr = JsonSerializer.Serialize(obj,options);
    

提交回复
热议问题