zoukankan      html  css  js  c++  java
  • aspnetcore 取消默认Json首字母小写

            public void ConfigureServices(IServiceCollection services)
            {
                // 根据类是否添加注解[IsService]来自动注入
                var assm = new[] { typeof(Program).Assembly, typeof(DbCtxt).Assembly };
                foreach (var ass in assm)
                {
                    var types = ass.GetTypes();
                    foreach (var typ in types)
                    {
                        var typeInfo = typ.GetTypeInfo();
                        if (typeInfo.IsDefined(typeof(IsServiceAttribute)))
                        {
                            services.AddScoped(typ);
                            var interfaces = typeInfo.ImplementedInterfaces;
                            foreach (var item in interfaces)
                            {
                                services.AddScoped(item, typ);
                            }
                        }
                    }
                }
    
                services.AddControllers();
    
                services.AddMvc(op => op.Filters.Add(typeof(TransActionFilter)))
                .AddJsonOptions(op =>
                {
                    op.JsonSerializerOptions.PropertyNameCaseInsensitive = true;
                    op.JsonSerializerOptions.PropertyNamingPolicy = null;// 取消默认首字母小写
                });
            }
  • 相关阅读:
    oracle数据库闪回执行步骤——oracle数据库回退
    10.20总结
    10.11总结
    10.10总结
    10.9总结
    10.8总结
    10.7总结
    10.6总结
    10.5总结
    10.4总结
  • 原文地址:https://www.cnblogs.com/jonney-wang/p/13832806.html
Copyright © 2011-2022 走看看