方法一
WEB API默認支持返回XML和JSON 格式數據,其根據WEB請求中指定的類型自動識別,但在本項目中只需要用json格式,而且爲了在chrome中測試方便(用chrome瀏覽器默認返回是xml數據),限制其無論什麼情況都返回JSON格式。
在Application_Start中加上:
GlobalConfiguration.Configuration.Formatters.XmlFormatter.SupportedMediaTypes.Clear();
方法二
上法或者太暴力了,來個溫和點的
在Application_Start中加上:
GlobalConfiguration.Configuration.Formatters.JsonFormatter.MediaTypeMappings.Add(new
QueryStringMapping(“format”, “json”, “application/json”));