python - Why does json.load not read this?
问题描述
json
can't read more than 1 dictionary.
Code:
with open('jsonfile.json', 'r') as a:
o = json.load(a)
print(o)
jsonfile.json:
{
"1234567899": {
"username": "1",
"password": "1",
"email": "example@example.com"
}
},
{
"9987654321": {
"username": "2",
"password": "2",
"email": "example@example.com"
}
}
Error:
File "unknown", line 8
{
^ SyntaxError: invalid syntax
Why does the ,
not work to separate the json dictionaries?
解决方案
It is causing an error because it is an invalid JSON. One solution is to have one overall dictionary:
{
"1234567899": {
"username": "1",
"password": "1",
"email": "example@example.com"
},
"9987654321": {
"username": "2",
"password": "2",
"email": "example@example.com"
}
}
Another is to have a list containing your various dictionaries:
[{
"1234567899": {
"username": "1",
"password": "1",
"email": "example@example.com"
}
},
{
"9987654321": {
"username": "2",
"password": "2",
"email": "example@example.com"
}
}]
推荐阅读
- salesforce - 如何通过 Salesforce 的 RestAPi 连接和检索雪花(数据库)
- python-3.x - 使用 python 将 azure Runbook 与 azure 中的文件共享连接起来
- excel - 无法在 Excel VBA 中使用 InputBox 进行过滤
- c++ - 如何在 ROS 中获取 hector_quadrotor 的 z 位置?
- typescript - 检查对象是否至少具有指定的属性
- java - 不兼容的类型:JSONLoader 无法转换为 Loader
- cmake - 使用 cmake 构建 Fortran 共享库的奇怪问题
- java - 从服务器上部署的 Spring Boot 应用程序中读取 API 元数据
- laravel - Laravel 急切加载 - 一对多关系
- python - 读取字符串,计算出现次数而不使用 pYthon 中的循环