【问题标题】:How to pass the json file as input to json2html module?如何将 json 文件作为输入传递给 json2html 模块?
【发布时间】:2018-09-26 01:01:49
【问题描述】:

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

【问题讨论】:

  • 如何在 json2html.convert(json=input) 中传递一个 json 文件作为输入?

标签: python html json json2html


【解决方案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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-05-17
    • 1970-01-01
    • 2022-08-15
    • 1970-01-01
    • 2017-03-01
    • 1970-01-01
    • 2018-05-10
    相关资源
    最近更新 更多