如何转义 VSCode launcher.json 命令中作为参数传递的 json 中的逗号?

Cri*_*ano 4 visual-studio-code flutter vscode-debugger

我想调试一个应用程序,需要传递一个内联 json 作为 arg。我做了以下事情:

    "configurations": [
        {
            "name": "app DEV",
            "program": "lib/main.dart",
            "request": "launch",
            "type": "dart",
            "args": [
                "--dart-define=APP_BACKENDS={[{\"id\":\"default\",\"url\":\"https://localhost\",\"port\": \"8080\"},]}",
            ]
        }
Run Code Online (Sandbox Code Playgroud)

但 APP_BACKENDS const 值在第一个逗号中被删除。锁定它的打印:{[{"id":"default"


只是为了清楚起见。这就是我获取打印值的方式:

static const _APP_BACKENDS =
      String.fromEnvironment('APP_BACKENDS', defaultValue: '{}');
Run Code Online (Sandbox Code Playgroud)

Ind*_*jit 5

经过大量链接和阅读后,终于找到了一个 GitHub 问题https://github.com/microsoft/vscode/issues/98471,它解决了我的类似问题。如果您浏览该链接并阅读倒数第二条评论,它会解释有关 shell 引用的内容。

"configurations": [
    {
        "name": "app DEV",
        "program": "lib/main.dart",
        "request": "launch",
        "type": "dart",
        "args": [
            "--dart-define=APP_BACKENDS={[{\"id\":\"default\",\"url\":\"https://localhost\",\"port\": \"8080\"},]}",
        ],
        "argsExpansion": "none"
    }
Run Code Online (Sandbox Code Playgroud)

"argsExpansion": "none"将其添加到我的 launch.json 文件后,我能够运行代码,而无需添加其他答案中提到的额外 \ 或空格。我尝试在 vscode 文档中搜索此配置,但没有找到任何参考,但它对我有用。