<p>根据<a href="https://docs.python.org/3/library/json.html?highlight=jsondecodeerror" rel="nofollow noreferrer">Python JSON documentation</a></p>
<blockquote>
<p>If the data being deserialized is not a valid JSON document, a JSONDecodeError will be raised.</p>
</blockquote>
<p>由于不知道文件的内容,很难说什么是错误的,但我怀疑文件中的文本不是有效的JSON对象,或者更可能(根据“额外数据”搜索,回答<a href="https://stackoverflow.com/questions/21058935/python-json-loads-shows-valueerror-extra-data/51830719">here</a>)文件“data.JSON”包含多个JSON对象</p>
<p>例如,使用您的代码:
此文件工作正常</p>
<pre><code>{ "name":"John", "age":30, "car":null }
</code></pre>
<p>但是这个</p>
<pre><code>{ "name":"John", "age":30, "car":null }
{ "name":"John", "age":30, "car":null }
</code></pre>
<p>抛出相同的错误</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Users\a\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py",
line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "C:\Users\a\AppData\Local\Programs\Python\Python37-32\lib\json\__init__.py",
line 348, in loads
return _default_decoder.decode(s)
File "C:\Users\a\AppData\Local\Programs\Python\Python37-32\lib\json\decoder.py",
line 340, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 6 column 1 (char 55)
</code></pre>