JSON.NET Error Self referencing loop detected for type

后端 未结 25 3263
我在风中等你
我在风中等你 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:39

    I had this exception and my working solution is Easy and Simple,

    Ignore the Referenced property by adding the JsonIgnore attribute to it:

    [JsonIgnore]
    public MyClass currentClass { get; set; }
    

    Reset the property when you Deserialize it:

    Source = JsonConvert.DeserializeObject(JsonTxt);
    foreach (var item in Source)
            {
                Source.MyClass = item;
            }
    

    using Newtonsoft.Json;

提交回复
热议问题