JSON2HTML:无效的JSON列表python [英] JSON2HTML: Not a valid JSON list python

查看:178
本文介绍了JSON2HTML:无效的JSON列表python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要转换为HTML的文件中包含一个JSON.我在网上看到有一个名为json2html的python工具,可以帮我解决这个问题.

I have a piece of JSON in a file I would like to convert to HTML. I seen online there is a tool called json2html for python which takes care of this for me.

[{
    "name": "Steve",
    "timestampe": "2016-07-28 10:04:15",
    "age": 22
}, 
{
    "name": "Dave",
    "timestamp": "2016-07-28 10:04:15",
    "age": 34
}]

使用在线转换器工具时,以上是我的JSON- http://json2html.varunmalhotra.xyz/效果很好,并为我制作了一张漂亮的桌子.

Above is my JSON, when using the online converter tool - http://json2html.varunmalhotra.xyz/ it works great and produces a nice table for me.

但是,当我使用pip安装库并运行以下命令时:

However when I install the library using pip and run the following:

_json = [{
    "name": "Steve",
    "timestampe": "2016-07-28 10:04:15",
    "age": 22
}, 
{
    "name": "Dave",
    "timestamp": "2016-07-28 10:04:15",
    "age": 34
}]

print json2html.convert(json=_json)

我得到一个错误

 File "/root/.pyenv/versions/venv/lib/python2.7/site-packages/json2html/jsonconv.py", line 162, in iterJson
raise Exception('Not a valid JSON list')
 Exception: Not a valid JSON list

我什至通过 http://jsonlint.com/来运行json,它作为有效JSON返回.

I even ran the json through http://jsonlint.com/ and it came back as valid JSON.

我想知道是否有人可以解决此问题,或者可以为我指出正确的解决方法.在该库中找不到太多文档.

I was wondering if anyone would have a fix for this, or could point me in the right direction on how to solve this. I can't find much documentation on this library.

作为参考,这是pypi库的链接- https://pypi.python.org/pypi /json2html

For reference this is the link to the pypi library - https://pypi.python.org/pypi/json2html

我们将不胜感激,在此先感谢您!

Any help would be appreciated, thanks in advance!

推荐答案

参数json必须是字典对象,并且您要传递列表. 试试这个:

parameter json must be a dictionary object and you pass a list. try this:

_json = { "data" : [{"name": "Steve",
    "timestampe": "2016-07-28 10:04:15",
    "age": 22
}, 
{
    "name": "Dave",
    "timestamp": "2016-07-28 10:04:15",
    "age": 34
}]
}
print json2html.convert(json=_json)

这篇关于JSON2HTML:无效的JSON列表python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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