简体   繁体   English

json.decoder.JSONDecodeError:期望用双引号括起来的属性名称:第 2 行第 2 列(字符 3)

[英]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.

相关问题 json.decoder.JSONDecodeError:期望属性名称用双引号引起来:读取 json 时第 2 行第 1 列(char 2)? - json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) when reading a json? json.decoder.JSONDecodeError:期望用双引号括起来的属性名称:第 2 行第 1 列(字符 2) - json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 2) json.decoder.JSONDecodeError:期望值:,json.decoder.JSONDecodeError:期望属性名称用双引号引起来: - json.decoder.JSONDecodeError: Expecting value: , json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: 如何解决 instascrape 标头中的“json.decoder.JSONDecodeError:期望用双引号括起来的属性名称”? - How to resolve "json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes" in headers for instascrape? JSONDecodeError:需要用双引号括起来的属性名称:第 2 行第 6 列(字符 6) - JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 6 (char 6) JSONDecodeError:期望用双引号括起来的属性名称:第 1 行第 3 列(字符 2) - JSONDecodeError: Expecting property name enclosed in double quotes: line 1 column 3 (char 2) json.decoder.JSONDecodeError:期望值:第2行第1列(char 1)错误 - json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1) error 错误:json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - ERROR: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 奇怪的“json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)” - WEIRD "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM