JSON解析Windows文件路径

标签 json atom-editor

我想在我的远程 ftp Atom 配置中指定一个 Windows 文件路径来引用我的私钥,但我遇到了一些解析问题。这是我的配置:

{
    "protocol": "sftp",
    "host": "somehost.com",
    "port": 22,
    "user": "haha",
    "pass": "testpass",
    "promptForPass": false,
    "remote": "/",
    "local": "",
    "agent": "",
    "privatekey": "C:\Users\haha\Documents\Keys\test_private_key.ppk",
    "passphrase": "",
    "hosthash": "",
    "ignorehost": true,
    "connTimeout": 10000,
    "keepalive": 10000,
    "keyboardInteractive": false,
    "keyboardInteractiveForPass": false,
    "remoteCommand": "",
    "remoteShell": "",
    "watch": [],
    "watchTimeout": 500
}

出现错误:

解析错误:“privatekey”:“C:\Users\haha\Docum

那么知道如何转义 Windows 文件路径以进行 JSON 解析吗?

最佳答案

您的 JSON 无效,因为反斜杠需要根据 spec 进行转义.

A string is a sequence of zero or more Unicode characters, wrapped in double quotes, using backslash escapes

因此,privateKey 的值应为"C:\\Users\\haha\\Documents\\Keys\\test_private_key.ppk"

关于JSON解析Windows文件路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57165074/

相关文章:

javascript - 使用 JSON 调用 API

c# - 使用 DataContractJsonSerializer 对 JSON 对象进行部分反序列化

安卓 : java. lang.OutOfMemoryError : Failed to allocate with free bytes and 70MB until OOM when using gson. toJson()

javascript - ASP.Net Core 3 将 JSON 数组发布到 Controller

javascript - 无法使用脚本包在 Atom 中运行 JavaScript

encoding - 如何 “save with encoding”

java - Android 将 JSON 发送到 PHP

javascript - 如何将一个html页面链接到另一个文件夹中的另一个页面

linux - Windows 插入未知字符。在 Linux bash 中显示为 ^?

multiline - Atom 上的多行编辑