appsettings with special characters in .NET Core

后端 未结 2 1065
灰色年华
灰色年华 2021-01-04 02:11

I have a small .NET Core console app which has an appsettings.json file containing different configuration sections and some of the values contain accents (for

2条回答
  •  长情又很酷
    2021-01-04 02:40

    JSON mandates UTF-8 as the file encoding. Your file is most likely saved in some other encoding, possibly Codepage 1252. Make sure you save the file as UTF-8 and your characters will work.

    Different tools handle this differently.

    For Notepad there's an Encoding selection in the Save dialog:

    Visual Studio has a Save with Encoding option in the Save dialog:

    You could also write a small program or script to do the conversion, e.g. the following PowerShell pipeline:

    (Get-Content appsettings.json) | Set-Content -Encoding Utf8 appsettings.json
    

提交回复
热议问题