Python json.decoder.JSONDecodeError:额外数据:第2行第1列(char 190)

Python json.decoder.JSONDecodeError:额外数据:第2行第1列(char 190),python,json,python-3.x,Python,Json,Python 3.x,我正在运行以下代码- import json addrsfile = open("C:\\Users\file.json", "r") addrJson = json.loads(addrsfile.read()) addrsfile.close() if addrJson: print("yes") 但是给我以下的错误- 回溯(最近一次呼叫最后一次): 文件“C:/Users/Mayur/Documents/WebPython/Python\u WebServices/test

我正在运行以下代码-

import json

addrsfile = 
open("C:\\Users\file.json", 
"r")
addrJson = json.loads(addrsfile.read())
addrsfile.close()
if addrJson:
    print("yes")
但是给我以下的错误-

回溯(最近一次呼叫最后一次):
文件“C:/Users/Mayur/Documents/WebPython/Python\u WebServices/test.py”,第9行,在
addrJson=json.load(addrsfile.read())
文件“C:\Users\Mayur\Anaconda3\lib\json\\uuuuu init\uuuuu.py”,第354行,加载
返回\u默认\u解码器。解码
文件“C:\Users\Mayur\Anaconda3\lib\json\decoder.py”,第342行,在decode中
raise JSONDecodeError(“额外数据”,s,结束)
json.decoder.JSONDecodeError:额外数据:第2行第1列(char 190)
有人帮我吗

JSON文件类似于-

{"name": "XYZ", "address": "54.7168,94.0215", "country_of_residence": "PQR", "countries": "LMN;PQRST", "date": "28-AUG-2008", "type": null}
{"name": "OLMS", "address": null, "country_of_residence": null, "countries": "Not identified;No", "date": "23-FEB-2017", "type": null}

json文件中有两条记录,
json.loads()
无法解码多条记录。你需要一个记录一个记录地做

或者您需要重新格式化json以包含数组:

{
    "foo" : [
       {"name": "XYZ", "address": "54.7168,94.0215", "country_of_residence": "PQR", "countries": "LMN;PQRST", "date": "28-AUG-2008", "type": null},
       {"name": "OLMS", "address": null, "country_of_residence": null, "countries": "Not identified;No", "date": "23-FEB-2017", "type": null}
    ]
}

也可以接受。但不能有多个顶级对象

我从REST API调用解析JSON时遇到了这个错误。结果证明,API变得更加“挑剔”(例如关于参数顺序等),因此返回的结果格式错误。检查您是否得到了预期的结果:)

如果字符串中有
json.loads()
无法识别的部分,也会显示此错误。在此示例字符串中,将在字符27
(char 27)
处引发错误

我的解决方案是使用
string.replace()
将这些项转换为字符串:

import json

string = """[{"Item1": "One", "Item2": False}, {"Item3": "Three"}]"""

string = string.replace("False", '"False"')

dict_list = json.loads(string)

您的json文件有问题。它可能格式不正确。谢谢@Hannu我按照你的建议重新格式化了Json。现在开始工作了。谢谢兄弟!对,在我的情况下,那个文件里有20000条记录。答案中建议的链接为我提供了解决方案。
import json

string = """[{"Item1": "One", "Item2": False}, {"Item3": "Three"}]"""

string = string.replace("False", '"False"')

dict_list = json.loads(string)