今天在发布接口的时候出忽然出现了一个问题,报错代码为:web
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]'.
通过研究,解决方法以下:json
找到相应的属性,添加 attribute:[IgnoreDataMember]api
还有时候会出现特殊状况,即便标记以上的attribute也不能解决app
具体错误为: oop
Newtonsoft.Json.JsonSerializationException 时 Self referencing loop detected for property *****
能够在web api的config中(WebApiConfig.cs)添加一下代码,用以过滤掉此问题code
奉上代码:orm
1 config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;