共計 275 個字符,預計需要花費 1 分鐘才能閱讀完成。
要讀取和解析 JSON 文件,可以使用 Python 的內置模塊 json。以下是一個簡單的示例:
import json
# 讀取 JSON 文件
with open('data.json', 'r') as file:
data = json.load(file)
# 解析 JSON 數據
for key, value in data.items():
print(key, value)
在上面的示例中,我們首先使用 open 函數打開一個 JSON 文件,然后使用 json.load 方法加載文件中的數據。接著,我們遍歷數據并打印鍵值對。
丸趣 TV 網 – 提供最優質的資源集合!
正文完