{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"AllowedHosts": "*",
"phone-segment": {
"中国电信": "133,153,189,180,181,177,173,199,174,141",
"中国移动": "139,138,137,136,135,134,159,158,157,150,151,152,147,188,187,182,183,184,178,198",
"中国联通": "二次测试,131,132,146,156,155,166,186,185,145,175,176",
"aa": "测试,171",
"内部号码": "123"
}
}
private void CreatePhoneValidator(IServiceCollection services)
{
Hashtable segment = new Hashtable();
//提取appsettings.json文件
var coll = Configuration.GetSection("phone-segment").GetChildren();
foreach (var prefix in coll)
{
if (string.IsNullOrEmpty(prefix.Value))
continue;
foreach (var s in prefix.Value.Split(','))
segment[s] = s;
}
var pv = new PhoneValidator(segment);
services.AddSingleton<PhoneValidator>(pv);
}
我们需要双击点进appsettings.json 然后点高级保存选项 选择 utf-8 with sign保存,之前我一直在其他页面设置这个并没用,必须点进文件 这时候在运行调试 就会发现中文不再乱码了.