Visual Studio 2017 or 2019 does not think about this at all, since Visual Studio itself requires that the output be in json format, and the default Visual Studio format is " XmlFormat" (config.Formatters.XmlFormatter) .
Visual Studio should do this automatically, and not give developers so much trouble.
To fix this problem, go to the WebApiConfig.cs file and add
var json = config.Formatters.JsonFormatter; json.SerializerSettings.PreserveReferencesHandling = Newtonsoft.Json.PreserveReferencesHandling.Objects; config.Formatters.Remove (config.Formatters.XmlFormatter);
after " config.MapHttpAttributeRoutes (); " in the Register method (HttpConfiguration configuration) . This will allow your project to produce json output.
William Hou Apr 30 '19 at 20:27 2019-04-30 20:27
source share