MVC api json 格式

 输出json

           var formatters = config.Formatters.Where(formatter =>
                   formatter.SupportedMediaTypes.Where(media =>
                   media.MediaType.ToString() == "application/xml" || media.MediaType.ToString() == "text/html").Count() > 0) 

//找到请求头信息中的介质类型 .ToList(); foreach (var match in formatters) { config.Formatters.Remove(match); //移除请求头信息中的XML格式 }

输出xml  

   在globle 中加入。。

GlobalConfiguration.Configuration.Formatters.XmlFormatter.UseXmlSerializer = true;

C# json 写法

转载 请注明原文地址并标明转载:http://www.cnblogs.com/laopo 商业用途请与我联系:lcfhn168@163.com
原文地址:https://www.cnblogs.com/laopo/p/4874105.html