我想在我的远程 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/