首页 > 解决方案 > json.decoder.JSONDecodeError: Expecting value: , json.decoder.JSONDecodeError: Expecting property name 括在双引号中:

问题描述

嗨,我正在 Python 文件中使用 JSON:

import json
userData = '''[
{
    "userID" : "20",
    "devices" : {
        "360020000147343433313337" : "V33_03",
        "3f0026001747343438323536" : "Door_03",
        "170035001247343438323536" : "IR_06",
        "28004c000651353530373132" : "BED_17"
    }
},

]'''

info = json.loads(userData)

加载时出现此错误: json.decoder.JSONDecodeError: Expecting value:

或者有时当我添加一些东西时: json.decoder.JSONDecodeError: Expecting property name 括在双引号中:

标签: pythonjsonpython-jsonschema

解决方案


尝试使用ast模块

前任:

import ast
userData = '''[
{
    "userID" : "20",
    "devices" : {
        "360020000147343433313337" : "V33_03",
        "3f0026001747343438323536" : "Door_03",
        "170035001247343438323536" : "IR_06",
        "28004c000651353530373132" : "BED_17"
    }
},
]'''

info = ast.literal_eval(userData)
print(info)

推荐阅读