在Sublime Text中使用JSON配置文件中的註釋可能會使JSON對象無法解碼。這是我的故事。爲什麼Sublime Text 3允許在JSON配置文件中添加註釋?
我在我的Sublime Text 3中新安裝了SublimeREPL插件3.很快,我發現它默認運行Python2.7而不是3.5,所以我根據SublimeREPL Docs添加了自己的Python3.5配置文件,以支持Python3.5。
我Packages/SublimeREPL/config/Python3.5/Main.sublime-menu
JSON配置文件看起來是這樣的:
[
{
"id": "tools",
"children":
[{
"caption": "SublimeREPL",
"mnemonic": "R",
"id": "SublimeREPL",
"children":
[
{"caption": "Python3.5",
"id": "Python3.5",
"children":[
{"command": "repl_open",
"caption": "Python3.5",
"id": "repl_python3.5",
"mnemonic": "P",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-i", "-u"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python3",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
},
// run files
{"command": "repl_open",
"caption": "Python3.5 - RUN current file",
"id": "repl_python3.5_run",
"mnemonic": "R",
"args": {
"type": "subprocess",
"encoding": "utf8",
"cmd": ["python3", "-u", "$file_basename"],
"cwd": "$file_path",
"syntax": "Packages/Python/Python.tmLanguage",
"external_id": "python3",
"extend_env": {"PYTHONIOENCODING": "utf-8"}
}
}
]}
]
}]
}]
注有評論//在這個文件中運行的文件。這個配置工作正常,從菜單欄工具 - > SublimeREPL-> Python3.5。然而,當我試圖F5鍵綁定repl_python3.5_run有更容易獲得3.5,以下異常被拋出在控制檯:
Traceback (most recent call last):
File "./python3.3/json/decoder.py", line 367, in raw_decode
StopIteration
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/opt/sublime_text/sublime_plugin.py", line 551, in run_
return self.run(**args)
File "/home/ubuntu/.config/sublime-text-3/Packages/SublimeREPL/run_existing_command.py", line 32, in run
json_cmd = self._find_cmd(id, path)
File "/home/ubuntu/.config/sublime-text-3/Packages/SublimeREPL/run_existing_command.py", line 41, in _find_cmd
return self._find_cmd_in_file(id, file)
File "/home/ubuntu/.config/sublime-text-3/Packages/SublimeREPL/run_existing_command.py", line 53, in _find_cmd_in_file
data = json.loads(bytes)
File "./python3.3/json/__init__.py", line 316, in loads
File "./python3.3/json/decoder.py", line 351, in decode
File "./python3.3/json/decoder.py", line 369, in raw_decode
ValueError: No JSON object could be decoded
之後我刪除了//運行文件發表評論。 F5鍵工作正常。這正是導致問題的評論。 Sublime Text使用JSON作爲配置文件,很多配置文件都帶有//樣式註釋。正如我們所知,設計中將註釋從JSON中移除。
然後,如何使Sublime文本允許在配置文件中進行註釋,是否使用管道?如果是這樣,我的密鑰綁定怎麼會失敗?
** P租賃不要以文本形式發佈**。將文本複製並粘貼到您的問題中。圖像無法搜索,屏幕閱讀器無法解讀視覺障礙者的圖像。使用[編輯]鏈接修改您的問題。有關更多信息,請參見[this](http://meta.stackoverflow.com/a/285557/1426065)。 – MattDMo
你說得對。我已經糾正了我的錯誤。感謝你指出了它。@ MattDMo – Naomi