.net core webapi return json capitalized, time format, null values and other issues deal

 

Return json capitalized, time format, null values ​​and other issues deal

In the Startup public void ConfigureServices (IServiceCollection services) add the following code function
 


            services.AddControllers().AddNewtonsoftJson(options =>
            {
                // 忽略循环引用
                options.SerializerSettings.ReferenceLoopHandling = ReferenceLoopHandling.Ignore;
                // 不使用驼峰
                options.SerializerSettings.ContractResolver = new DefaultContractResolver();
                // 设置时间格式
                options.SerializerSettings.DateFormatString = "yyyy-MM-dd HH:mm:ss";
                // 如字段为null值,该字段不会返回到前端
                // options.SerializerSettings.NullValueHandling = NullValueHandling.Ignore;
            });

 

 

Published 12 original articles · won praise 0 · Views 652

Guess you like

Origin blog.csdn.net/oopxiajun2011/article/details/104874062