溫馨提示×

Python怎么加載JSON文件

小億
272
2024-03-05 15:31:00
欄目: 編程語言

在 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ù)進行操作。

0