码迷,mamicode.com
首页 > Web开发 > 详细

Json序列化循环引用的问题

时间:2017-03-31 10:30:37      阅读:599      评论:0      收藏:0      [点我收藏+]

标签:webapi   form   loop   sample   blog   ons   mat   gen   oop   

今天在发布接口的时候出突然出现了一个问题,报错代码为:

1 An exception has occurred while using the formatter JsonMediaTypeFormatter to generate sample for media type application/json.
2 Exception message: Self referencing loop detected for property ****** with type ******. Path [0].******[0].

 

技术分享

经过研究,解决方法如下:

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

 


 

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

具体错误为: 

Newtonsoft.Json.JsonSerializationException 时 Self referencing loop detected for property *****

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

技术分享

 奉上代码:

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

 

 问题迎刃而解

 

Json序列化循环引用的问题

标签:webapi   form   loop   sample   blog   ons   mat   gen   oop   

原文地址:http://www.cnblogs.com/guess/p/6649739.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!