webapi返回json设置

    using Newtonsoft.Json;
    using Newtonsoft.Json.Serialization;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web.Http;

    namespace MvcApplication2
    {
        public static class WebApiConfig
        {
            public static void Register(HttpConfiguration config)
            {
                config.Routes.MapHttpRoute(
                    name: "DefaultApi",
                    routeTemplate: "{controller}/{action}/{parm}",
                    defaults: new { parm = RouteParameter.Optional }
                );
                config.EnableSystemDiagnosticsTracing();
                config.Formatters.Remove(config.Formatters.XmlFormatter);
                var jsonFormatter = config.Formatters.JsonFormatter;
                jsonFormatter.SerializerSettings.Formatting = Formatting.Indented;
                jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
            }
        }
    }
阅读更多
个人分类: webapi
下一篇c# mysqlhelper
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭