[英]json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 2 (char 3)
I know this Question is already answered, but I dont know where the Error is in my Case.我知道这个问题已经得到解答,但我不知道我的案例中的错误在哪里。
This is my Code:这是我的代码:
import json
json_data = """
{
'position1': '516, 440',
'position2': '971, 443',
'position3': '1186, 439',
'position4': '1402, 441',
'position5': '1630, 449',
'position6': '299, 681',
'position7': '518, 684',
'position8': '736, 691',
'position9': '739, 431'
}
"""
data = json.loads(json_data)
print(data)
Im not really into working with json files, so please don't blame me if it's a really dump mistake.我不太喜欢使用 json 文件,所以如果这是一个真正的转储错误,请不要怪我。
Don't use triple quotes """
. Instead use a dictionary with json.dumps()
so that commas in your values are not misinterpreted as commas between items.不要使用三引号
"""
。而是使用带有json.dumps()
的字典,这样您的值中的逗号不会被误解为项目之间的逗号。
import json
json_data = {
'position1': '516, 440',
'position2': '971, 443',
'position3': '1186, 439',
'position4': '1402, 441',
'position5': '1630, 449',
'position6': '299, 681',
'position7': '518, 684',
'position8': '736, 691',
'position9': '739, 431'
}
data = json.dumps(json_data)
print(data)
If you are using triple quotes, this would work如果您使用三引号,这将起作用
json_data = json_data.replace("'", '"')
data = json.loads(json_data)
print(data)
Try this one试试这个
import json
json_data = {
'position1': '516, 440',
'position2': '971, 443',
'position3': '1186, 439',
'position4': '1402, 441',
'position5': '1630, 449',
'position6': '299, 681',
'position7': '518, 684',
'position8': '736, 691',
'position9': '739, 431'
}
data = json.dumps(json_data)
print(data)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.