更新时间:2022-02-12 08:35:25
要阻止发生的历史的错误的***方法是:
The best way to stop that error from occuring is:
在您的WebAPI项目进入App_Start文件夹,并添加到WebApiConfig code这四行:
In your WebApi project go to the App_Start folder and add to the WebApiConfig this four lines of code:
config.EnableSystemDiagnosticsTracing();
config.Formatters.JsonFormatter.SerializerSettings.PreserveReferencesHandling = PreserveReferencesHandling.None;
config.Formatters.JsonFormatter.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
config.Formatters.JsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
config.Formatters.Remove(config.Formatters.XmlFormatter);
和确保你已经instaled JSON的包的NuGet
and make sure you have instaled the Json nuget package