本文介绍了JSON.Net自我参照循环检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个MSSQL数据库4表中我的网站。
当我使用这样的:
公共静态字符串GetAllEventsForJSON()
{
使用(CyberDBDataContext DB =新CyberDBDataContext())
{
返回JsonConvert.SerializeObject((从在db.Events那里a.Active选择).ToList(),新JavaScriptDateTimeConverter());
}
}
在code会导致以下错误:
解决方案
I just had the same plroblem with Parent/Child collections and found that post which has solved my case.I Only wanted to show the List of parent collection items and didn't need any of the child data, therefore i use the following and it worked fine:
JsonConvert.SerializeObject(ResultGroups, Formatting.None,
new JsonSerializerSettings()
{
ReferenceLoopHandling = ReferenceLoopHandling.Ignore
});
JSON.NET Error Self referencing loop detected for type
it also referes to the Json.NET codeplex page at:
http://json.codeplex.com/discussions/272371
Documentation: ReferenceLoopHandling setting
这篇关于JSON.Net自我参照循环检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!