python - 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 括在双引号中:
解决方案
尝试使用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)
推荐阅读
- python - 连接表(1:多表关系)的正确 SQLAlchemy ORM 结构是什么?
- javascript - Django 在模板标签中使用变量
- python - Aiogram python InlineKeyboard
- c - 如何在一个结构中定义一个结构并重复使用相同的名称两次?
- java - Micronaut 和 Gradle 无法进行测试
- telegram - 是否可以使用电报机器人内联按钮来获取用户实时位置?
- php - 从 php 在命名管道上运行 shell 命令
- sql - SQL 拆分总计
- linux - org.eclipse.swt.SWTError: 没有更多句柄 [gtk_init_check() failed]
- html - 视频不会在移动 Safari 和 Firefox 上自动播放