[英]json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) when reading a json?
{
"teams": {
"sp": [
{
"k": {
"attack": 3,
"defense": 4
},
"s": {
"attack": 3,
"defense": 4
},
"b": {
"attack": 3,
"defense": 4
},
"h": {
"attack": 3,
"defense": 4
},
"r": {
"attack": 3,
"defense": 4
},
"l": {
"attack": 4,
"defense": 5
}
}
],
"mu": [
{
"r": {
"attack": 5,
"defense": 6
},
"a": {
"attack": 4,
"defense": 3
},
"f": {
"attack": 4,
"defense": 3
},
"c": {
"attack": 4,
"defense": 3
},
"v": {
"attack": 4,
"defense": 2
},
"dg": {
"attack": 4,
"defense": 5
}
}
]
}
}
Code代码
obj = [json.loads(line) for line in open('playerlist.json', 'r')]
print(obj)
the above json
is player list and below is the python code I'm trying to read it with.上面的
json
是播放器列表,下面是我试图读取它的 python 代码。 when I run it it raise当我运行它时它会升高
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2)
I've read its a formatting issue with the json
but when I run it through a json
formatted it says it is valid json
.我已经阅读了它的
json
格式问题,但是当我通过json
格式运行它时,它说它是有效的json
。
The issue is that you are trying to convert individual lines to json
, you need to convert the all file at once问题是您正在尝试将单行转换为
json
,您需要一次转换所有文件
with open('playerlist.json', 'r') as f:
obj = json.load(f)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.