在Python中将JSON转换为HTML表格 [英] Converting JSON to HTML table in Python

查看:3657
本文介绍了在Python中将JSON转换为HTML表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

  infoFromJson = json。加载(jsonfile)

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



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



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



有没有人有过使用此工具的经验?或者是否有人对替代方案有任何建议?

解决方案

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

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



如果您没有 json2html 模块的问题:

  $ pip install json2html 

更多示例此处


I've been using the JSON library for Python to get data from JSON files using Python.

infoFromJson = json.loads(jsonfile)

I fully understand how to work with JSON files in Python. However, I am trying to find a way to format JSON format in a nice way.

I prefer to convert the JSON into a nested HTML table format.

I found json2html for Python, which does exactly what I just described. However, it does not actually output anything when I run the script they provide.

Has anyone had experience with this tool? Or does anyone have suggestions for alternatives?

解决方案

Try the following:

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

The result from json2html.convert is a string.

If you don't have module:

$ pip install json2html

More examples here.

这篇关于在Python中将JSON转换为HTML表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆