【发布时间】:2021-06-13 11:21:49
【问题描述】:
我在appsettings 文件中有以下 JSON,它有一个连接字符串。
{
"Logging": {
"LogLevel": {
"Default": "Warning"
}
},
"ApplicationInsights": {
"InstrumentationKey": "8eje88w0-1509-4ae0-b58c-1a7ee5b9c7e4"
},
"ConnectionStrings": {
"DefaultConnString": "Server=MYPC\SQLEXPRESS;Database=CoreService.Mark;Trusted_Connection=True;"
},
"AllowedHosts": "*"
}
但是在执行程序时,我不断收到以下错误。我试图找到任何错误,但找不到任何错误。请指教
Unhandled exception. System.FormatException: Could not parse the JSON file.
---> System.Text.Json.JsonReaderException: 'S' is an invalid escapable character within a JSON string. The string should be correctly escaped. LineNumber: 10 | BytePositionInLine: 42
【问题讨论】:
-
反斜杠必须转义。
-
要么使用正斜杠,要么使用两次反斜杠
-
来自 Json.org 的 Json 字符串定义:json.org/img/string.png
标签: c# json .net appsettings