0

我是 python 新手,但我设法编写了一个简单的代码,通过 json2html 模块将 json 数据生成为 html 格式。json2html.convert(json=input),在这里当我传递 json 节点时,它是工作文件,但我应该传递从我的应用程序创建的 json 文件作为输入到 json2html 以生成 html 表格式。我怎么能传递任何 json 文件作为将文件转换为 html 表的输入?

4

1 回答 1

1

您可以尝试使用json2table模块,至少我是这样做的。以下代码创建一个包含所有 json 数据表结构的 html 文件。

from json2table import *
import json


data = open('YOURFILE.json','r')
jsonFile = data.read()
foo = json.loads(jsonFile)
build_dir = "LEFT_TO_RIGHT"
table_attr = {"style" : "width:100%", "class" : "table table-striped"}
html = convert(foo, build_direction=build_dir,table_attributes=table_attr)

with open("YOURFILE.html", "w") as ht:
    ht.write(html)
于 2018-05-08T13:41:53.503 回答