JSON.NET Error Self referencing loop detected for type

后端 未结 25 3230
我在风中等你
我在风中等你 2020-11-22 02:16

I tried to serialize POCO class that was automatically generated from Entity Data Model .edmx and when I used

JsonConvert.SerializeObject 

25条回答
  •  离开以前
    2020-11-22 02:34

    You can apply an attribute to the property too. The [JsonProperty( ReferenceLoopHandling = ... )] attribute is well suited to this.

    For example:

    /// 
    /// Represents the exception information of an event
    /// 
    public class ExceptionInfo
    {
        // ...code omitted for brevity...
    
        /// 
        /// An inner (nested) error.
        /// 
        [JsonProperty( ReferenceLoopHandling = ReferenceLoopHandling.Ignore, IsReference = true )]
        public ExceptionInfo Inner { get; set; }
    
        // ...code omitted for brevity...    
    }
    

    Hope that helps, Jaans

提交回复
热议问题