.Net Core 读取appsettings.json 文件时出现中文乱码

¥10.00

appsettings.json配置如下:

 {
 "Meta": {
    "Title": "我是标题",
    "Keywords": "我是关键字",
    "Description": "我是内容描述"
  },
 }

读取appsettings.json的代码如下:

  public static string SeoTitle = DbHelper.ConfigurationManager.Configuration.GetSection("SeoMeta")["Title"];
  public static string SeoKeywords = DbHelper.ConfigurationManager.Configuration.GetSection("SeoMeta")["Keywords"];
   public static string SeoDescription = DbHelper.ConfigurationManager.Configuration.GetSection("SeoMeta")["Description"];
@page "{handler?}"
@model IndexModel
@{
    ViewData["Title"] = @Html.Raw(Config.SeoTitle);
    ViewData["Keywords"] = @Html.Raw(Config.SeoKeywords);
    ViewData["Description"] = @Html.Raw(Config.SeoDescription); 
}

但页面编译后,所有中文字全部变成了乱码?请教各位,如何解决此问题?在线等

desaco T0 发布于2年前

最佳解决方案

appsettings.json 文件编码问题

用记事本打开appsettings.json 文件,另存为-编码选择UTF-8,保存即可
1604974917(1).jpg


田田 T1 被采纳率33%
2020-11-10 10:22
打赏 0 1
页面统计
1811 访问
0 帮助
0.00 打赏

hierror 2019 © hierror.com 京ICP备13026190号-1

通知消息
  • 暂无任何消息