产生原因:
model类添加了 [System.Serializable]
解决方案:
xxxxx.WebApiApp_StartWebApiConfig.cs的Register函数中添加如下代码
config.Formatters.XmlFormatter.UseXmlSerializer = true; config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("$Format", "xml", "application/xml")); config.Formatters.XmlFormatter.MediaTypeMappings.Add(new QueryStringMapping("OutputFormat", "xml", "application/xml")); config.IncludeErrorDetailPolicy = IncludeErrorDetailPolicy.Always; var serializerSettings = GlobalConfiguration.Configuration.Formatters.JsonFormatter.SerializerSettings; var contractResolver = (DefaultContractResolver)serializerSettings.ContractResolver; contractResolver.IgnoreSerializableAttribute = true; //config.Formatters.Insert(0, new JsonpFormatter()); config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = Newtonsoft.Json.ReferenceLoopHandling.Ignore; config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.None; config.Formatters.JsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver(); config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("$Format", "json", "application/json")); config.Formatters.JsonFormatter.MediaTypeMappings.Add(new QueryStringMapping("OutputFormat", "json", "application/json"));