【发布时间】:2014-08-07 16:37:59
【问题描述】:
我看到其他人在尝试将具有导航属性的实体序列化到其他实体的集合(例如父子关系中)时添加了此错误的问题。
The 'ObjectContent`1' type failed to serialize the response body for content type 'application/json; charset=utf-8'.",
我已经尝试将这些选项添加到 WebApiConfig.cs 文件中的 Register 方法中,但我仍然遇到同样的错误。
var json = config.Formatters.JsonFormatter;
json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects;
config.Formatters.Remove(config.Formatters.XmlFormatter);
json.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore;
【问题讨论】:
标签: asp.net-web-api json.net entity-framework-6