JSON双引号之谜

时间:2019-12-16 20:26:38

标签: python json python-3.x

倾斜的JSON,我想认为它遵循tee的语法提示。我想开始将数据集加载到JSON中并使用Python进行操作。编写数据集后,我开始输入数据,但一直出现此错误。

json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 7 column 2 (char 129)

尽管我遵循了多个教程,但我无法理解错误的出处?

        [
            {
                "name": "x",
                "email": "x@x",
                "location": "Yorkville Village",
                "contacted": "Yes",
            },
            {
                "name": "y",
                "email": "y@y",
                "location": "Yorkville Village",
                "contacted": "Yes",
            },
            {
                "name": "z",
                "email": "info@z.com",
                "location": "Yorkville Village",
                "contacted": "Yes",
            },
        ]

2 个答案:

答案 0 :(得分:3)

期望“属性名称用双引号引起来”,如“期望[另一个]属性[名称]用双引号引起来”;期待另一个属性。这是因为k:v对的末尾有多余的逗号。

您要

        [
            {
                "name": "x",
                "email": "x@x",
                "location": "Yorkville Village",
                "contacted": "Yes"
            },
            {
                "name": "y",
                "email": "y@y",
                "location": "Yorkville Village",
                "contacted": "Yes"
            },
            {
                "name": "z",
                "email": "info@z.com",
                "location": "Yorkville Village",
                "contacted": "Yes"
            }
        ]

答案 1 :(得分:2)

由于每个对象中的最后一个逗号,因此您在问题中显示的Json无效。

这是有效版本:

[
    {
        "name": "x",
        "email": "x@x",
        "location": "Yorkville Village",
        "contacted": "Yes"
    },
    {
        "name": "y",
        "email": "y@y",
        "location": "Yorkville Village",
        "contacted": "Yes"
    },
    {
        "name": "z",
        "email": "info@z.com",
        "location": "Yorkville Village",
        "contacted": "Yes"
    }
]

始终使用JSON validator

检查您的JSON是否有效。