温馨提示×

Python怎么加载JSON文件

小亿
121
2024-03-05 15:31:00
栏目: 编程语言

在 Python 中加载 JSON 文件可以使用 json 模块。下面是一个示例代码:

import json

# 读取 JSON 文件
with open('data.json', 'r') as file:
    data = json.load(file)

# 输出数据
print(data)

在上面的代码中,json.load() 函数用于加载 JSON 文件并将其转换为 Python 对象。你可以通过 open() 函数打开 JSON 文件,使用 json.load() 函数加载数据,并对数据进行操作。

0