c# - JSON 解析问题 - 'S' 是 JSON 中无效的可转义字符

标签 c# json .net appsettings

我在 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/

相关文章:

java - 在java中将字符串转换为json

c# - 在 Linq 查询中检查对象是否为 Null

c# - Prism 绑定(bind)错误的 View 模型

c# - 一种 catch 现代编程技术的方法

java - JSON 中的 WebApplicationException 使用

javascript - 在 native react 中写入/编辑/覆盖 json 文件

c# - 在接口(interface)中创建通用属性

c# - HttpClient.GetAsync(...) 在使用 await/async 时永远不会返回

c# - ASP.NET MVC 2 应用程序中类似 Twitter 的路由

c# - 链中的多个后台 worker