为什么读取.json文件时出现此错误?

时间:2019-12-11 20:03:30

标签: python json file-handling

所以我有此功能来读取json文件并返回通过它的文件中数据的字典

def file_read(source):
    with open(source) as file:
        data = file.read()
        dictionary = json.loads(data)
        return dictionary

我正在使用的文件名为“ users.json”并已格式化

{"Jim":("password", "MMA60V")}

但是,每当我尝试运行代码以读取“ users.json”中的内容时,都会出现此错误

json.decoder.JSONDecodeError: Expecting value: line 1 column 8 (char 7)```

does anyone know why this is happening and a possible solution thank you.

1 个答案:

答案 0 :(得分:0)

那是不正确的JSON,并且由于您使用的是json.loads,因此会出现错误。

将JSON粘贴到https://jsonlint.com/中,您会看到输入无效。 JSON不支持元组。

相关问题