JSON.NET Error Self referencing loop detected for type

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

    To serialize usin NEWTONSOFTJSON when you have loop issue, in my case I did not need modify global.asax or either apiconfig. I just use JsonSerializesSettings ignoring Looping handling.

    JsonSerializerSettings jss = new JsonSerializerSettings();
    jss.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
    var lst = db.shCards.Where(m => m.CardID == id).ToList();
    string json = JsonConvert.SerializeObject(lst, jss);
    

提交回复
热议问题