Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 为什么在读取.json文件时会出现此错误?_Python_Json_File Handling - Fatal编程技术网

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

Python 为什么在读取.json文件时会出现此错误?,python,json,file-handling,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")} 但是,每当我尝

所以我有这个函数来读取一个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.

这不是正确的JSON,因为您使用的是
JSON.loads
,所以会出现错误


将JSON粘贴到中,您可以看到输入无效。JSON不支持元组。

请尝试:
{“Jim”:[“password”,“MMA60V”]}
JSON格式使用方括号
[]
表示数组。这很有效,谢谢你,我会在可能的情况下将其标记为答案