Python 为什么在读取.json文件时会出现此错误?
所以我有这个函数来读取一个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")} 但是,每当我尝
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格式使用方括号[]
表示数组。这很有效,谢谢你,我会在可能的情况下将其标记为答案