Python中可以使用json模块来解析JSON文件,并提取数据。下面是一个简单的示例:
import json# 读取JSON文件with open('data.json', 'r') as file: data = json.load(file)# 提取数据name = data['name']age = data['age']city = data['address']['city']print(f"Name: {name}")print(f"Age: {age}")print(f"City: {city}")在这个示例中,我们首先使用open()函数打开JSON文件,并使用json.load()函数将文件内容加载到一个Python对象中。
然后,我们可以通过访问Python对象的键来提取JSON数据。在这个示例中,我们提取了name、age和address中的city字段。
最后,我们使用print()函数打印提取到的数据。
请注意,这个示例假设JSON文件的结构如下:
{ "name": "John", "age": 30, "address": { "city": "New York" }}你需要根据你的JSON文件结构来提取数据。

