首页 > 解决方案 > Python json.loads 导致额外数据异常

问题描述

这是我的文件的样子:

在此处输入图像描述

我的代码

import json

with open(r'c:\sample.json') as json_file:
    data = json.load(json_file)

我得到了这个错误:

Extra data: line 18 column 2 (char 294)

这是什么意思 ?什么额外的数据?

标签: pythonjson

解决方案


一个json文件只能是一个数据结构,如果你想在里面放多个dict,那么你可以把它们放在一个列表中

[
    {...},
    {...},
    ...
]

推荐阅读