Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用PYTHON读取JSON文件并使用该数据创建excel文件_Python_Json_Excel - Fatal编程技术网

使用PYTHON读取JSON文件并使用该数据创建excel文件

使用PYTHON读取JSON文件并使用该数据创建excel文件,python,json,excel,Python,Json,Excel,我正在进行一个项目,在这个项目中,我必须读取一个JSON文件,然后将数据加载到excel文件中。我不知道如何在Python中实现这一点,我需要一些真正的帮助。 以下是JSON结构: {"Models":[{"name":"AAA", "text":"some text", "structure":[{"column":"zzz", "type":"string"}, .....]}, {"name":"BBB", "text":"some text", "structure":[{"column

我正在进行一个项目,在这个项目中,我必须读取一个JSON文件,然后将数据加载到excel文件中。我不知道如何在Python中实现这一点,我需要一些真正的帮助。 以下是JSON结构:

{"Models":[{"name":"AAA", "text":"some text", "structure":[{"column":"zzz", "type":"string"}, .....]}, {"name":"BBB", "text":"some text", "structure":[{"column":"zzz", "type":"string"}, .....]}]}
我需要将其转换为以下excel格式: 名称|列|类型 AAA | zzz |串 BBB | yyy |文本 CCC | xxx |串


由于列和类型位于不同的键下,而名称是不同的键,因此不确定如何执行此操作。

将json文件作为dict加载并迭代

import json

f = open("f.json")
data = json.load(f)
f.close()
for x in data.get('Models'):
    name = x.get('name')
    for s in x.get('structure'):
        #write this string to a csv file
        print(name + ' ' + s.get('column') + ' ' + s.get('type'))

这管用!非常感谢你。非常感谢您的帮助。在上面的代码中,我可以看到控制台中打印的数据。如何将其打印到excel文件?你能帮我吗?