繁体   English   中英

在Python中将JSON转换为HTML表

[英]Converting JSON to HTML table in Python

我一直在使用Python的JSON库来使用Python从JSON文件中获取数据。

infoFromJson = json.loads(jsonfile)

我完全理解如何在Python中使用JSON文件。 但是,我试图找到一种方法来以一种很好的方式格式化JSON格式。

我更喜欢将JSON转换为嵌套的HTML表格式。

我发现了Python的json2html ,它正是我刚才所描述的。 但是,当我运行它们提供的脚本时,它实际上并没有输出任何内容。

有没有人有这个工具的经验? 或者有没有人有替代方案的建议?

请尝试以下方法:

infoFromJson = json.loads(jsonfile)
print json2html.convert(json = infoFromJson)

json2html.convert的结果是一个字符串。

如果你没有模块:

$ pip install json2html

这里有更多例子。

现在最好使用json2table(至少对于Python 3)

import json2table
import json

infoFromJson = json.loads(jsonfile)
build_direction = "LEFT_TO_RIGHT"
table_attributes = {"style": "width:100%"}
print(json2table.convert(infoFromJson, 
                         build_direction=build_direction, 
                         table_attributes=table_attributes))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM