【发布时间】:2019-12-11 20:03:30
【问题描述】:
所以我有这个函数来读取一个 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.
【问题讨论】:
-
试试:
{"Jim":["password", "MMA60V"]}JSON 格式使用方括号[ ]表示数组。
标签: python json file-handling