如何将文件作为列表/字典读取?

Mic*_*hal 1 python dictionary file list

我有一个文件,其结构与python list/dictionaries相同,即

[
    {
      "key1" : "value1",
      "key2" : "value2",
       ...
    },
    {
      "key1" : "value3",
      "key2" : "value4",
      ...
    },
    ...
]
Run Code Online (Sandbox Code Playgroud)

有一些简单的方法如何读取此文件并将其转换为字典列表?

khe*_*ana 10

with open('your_file', encoding='utf-8') as data_file:
   data = json.loads(data_file.read())
Run Code Online (Sandbox Code Playgroud)