在 Python 中将 JSON 转换为 HTML table
Converting JSON to HTML table in Python
我一直在使用 Python 的 JSON 库,使用 Python 从 JSON 文件中获取数据。
infoFromJson = json.loads(jsonfile)
我完全理解如何使用 Python 中的 JSON 个文件。但是,我正在尝试找到一种很好地格式化 JSON 格式的方法。
我更喜欢将 JSON 转换为嵌套的 HTML table 格式。
我为 Python 找到了 json2html,这正是我刚才描述的。
但是,当我 运行 他们提供的脚本时,它实际上并没有输出任何东西。
有人用过这个工具吗?或者有人对替代方案有建议吗?
尝试以下操作:
infoFromJson = json.loads(jsonfile)
print(json2html.convert(json = infoFromJson))
json2html.convert
的结果是一个字符串。
如果您没有 json2html 模块:
$ pip install json2html
更多示例here。
现在最好使用 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))
我一直在使用 Python 的 JSON 库,使用 Python 从 JSON 文件中获取数据。
infoFromJson = json.loads(jsonfile)
我完全理解如何使用 Python 中的 JSON 个文件。但是,我正在尝试找到一种很好地格式化 JSON 格式的方法。
我更喜欢将 JSON 转换为嵌套的 HTML table 格式。
我为 Python 找到了 json2html,这正是我刚才描述的。 但是,当我 运行 他们提供的脚本时,它实际上并没有输出任何东西。
有人用过这个工具吗?或者有人对替代方案有建议吗?
尝试以下操作:
infoFromJson = json.loads(jsonfile)
print(json2html.convert(json = infoFromJson))
json2html.convert
的结果是一个字符串。
如果您没有 json2html 模块:
$ pip install json2html
更多示例here。
现在最好使用 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))