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 928
执念已碎
执念已碎 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:21

    Ensure you have [JsonIgnore] on the correct fields to avoid a circular reference.

    In this case you will need

     public class Product
    {
        public int Id { get; set; }
        public string Name { get; set; }
        public string ProductText { get; set; }
        [JsonIgnore]
        public virtual ProductCategory ProductCategory { get; set; }
    }
    

    You probably don't need the ProductCategoryId field (depends if you are using EF and code first to define your DB)

提交回复
热议问题