使用“python -m jsontool”从命令行验证 JSON 给出“无法解码 JSON 对象”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18922735/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
validating JSON from command line using `python -m jsontool` gives 'No JSON object could be decoded'
提问by 3cheesewheel
I have a data.json
file that I'm validating through the command line using python's json.tool, but it keeps giving me back an error message:
我有一个data.json
文件,我正在使用 python 的 json.tool 通过命令行验证该文件,但它不断给我返回一条错误消息:
$ python -m json.tool < data.json
No JSON object could be decoded
Here are the contents of data.json
:
以下是内容data.json
:
$ cat data.json
{ "fields":
[
[ "first_name", null, {} ],
[ "last_name", null, {} ],
[ "addr1", null, {} ],
[ "addr2", null, {} ],
[ "city", null, {} ],
]
}
I don't have a problem with single quotes, nor is the file empty (obviously), so I'm not sure what's causing the problem here.
我对单引号没有问题,文件也不是空的(显然),所以我不确定是什么导致了这里的问题。
采纳答案by 3cheesewheel
It was because of the trailing comma after the last nested list [ "city", null, {} ]
. I accidentally left it in and JSON doesn't allow them.
这是因为最后一个嵌套列表后面的逗号[ "city", null, {} ]
。我不小心把它留在了,JSON 不允许。