您的位置:首页 > Web前端 > JavaScript

[IgnoreDataMember]:json序列化循环引用的问题

2014-08-28 17:01 525 查看
An exception has occurred while using the formatter 'JsonMediaTypeFormatter' to generate sample for media type 'application/json'. Exception message: Self referencing loop detected for property '******' with type '******'. Path '[0].******[0]'.

找到相应的属性,添加attribute:[IgnoreDataMember]

 (System.Runtime.Serialization.dll)

------特殊情况分割线-------

还有时候会出现特殊情况,即使标记以上的attribute也不能解决

具体错误为: Newtonsoft.Json.JsonSerializationException 时 Self referencing loop detected for property *****

可以在web api的config中(WebApiConfig.cs)添加一下代码,用以过滤掉此问题

 

config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;


 

 
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
相关文章推荐