我在 appsettings
中有以下 JSON file ,它有一个连接字符串。
{
"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
最佳答案
在您的 ConnectionStrings. DefaultConnString
领域,你在逃避S
(之前 SQLExpress;
)。正如错误所暗示的那样,您不能这样做。
您可以通过在预先存在的转义字符前面添加另一个转义字符(反斜杠,\
)来解决此问题。反斜杠是可转义的字符,最终结果将是想要的字符,您将在该位置得到一个反斜杠。
关于c# - JSON 解析问题 - 'S' 是 JSON 中无效的可转义字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66650765/