在 Python 中加載 JSON 文件可以使用 json
模塊。下面是一個示例代碼:
import json
# 讀取 JSON 文件
with open('data.json', 'r') as file:
data = json.load(file)
# 輸出數(shù)據(jù)
print(data)
在上面的代碼中,json.load()
函數(shù)用于加載 JSON 文件并將其轉(zhuǎn)換為 Python 對象。你可以通過 open()
函數(shù)打開 JSON 文件,使用 json.load()
函數(shù)加載數(shù)據(jù),并對數(shù)據(jù)進行操作。