Python JSONDecodeError: 需要 ',' 分隔符:第 1 行第 43 列(字符 42)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/41262180/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 00:42:11  来源:igfitidea点击:

JSONDecodeError: Expecting ',' delimiter: line 1 column 43 (char 42)

python

提问by John Smith

I have read on many examples here already on SO. Unfortunately, I keep getting this error,

我已经在 SO 上阅读了许多示例。不幸的是,我不断收到此错误,

Error:

错误:

json.decoder.JSONDecodeError: Expecting ',' delimiter: line 1 column 43 (char 42)

json file:

json文件:

{"people": [{"name": "Scott", "from": "Nebraska", "website": "stackabuse.com"}, {"name": "Larry", "from": "Michigan", "website": "google.com"}, {"name": "Tim", "from": "Alabama", "website": "apple.com"}]}

And another separate json file:

另一个单独的 json 文件:

{"scores":[{"name":"Larry","result":["0":"24","1":"43","2":"56"]},{"name":"Tim","result":["0":"44","1":"29","2":"34"]}]}

python code:

蟒蛇代码:

with open('data.json') as file:
          data = json.load(file)

    print(data)

回答by Martijn Pieters

Your JSON is invalid, it has :tokens in an array:

您的 JSON 无效,它:在数组中有令牌:

"result": ["0": "24", "1": "43", "2": "56"]
#             ^          ^          ^

and

"result": ["0": "44", "1": "29", "2": "34"]
#             ^          ^          ^

Fix your JSON input; either replace those colons with commas, remove the "0":, "1":, and "2":'indices', or replace the [...]array brackets with {...}JSON object braces.

修复您的 JSON 输入;要么用逗号替换那些冒号,删除"0":"1":"2":“索引”,或更换[...]与阵列括号{...}JSON对象括号。

回答by Ohad the Lad

This is not a JSON, list or dict - not a python valid type:

这不是 JSON、列表或字典 - 不是 Python 有效类型:

["0":"24","1":"43","2":"56"]

in order to fix this and continue.

为了解决这个问题并继续。