PYTHON:JSON2XML转换问题

ztmd8pv5  于 2022-12-27  发布在  Python
关注(0)|答案(2)|浏览(119)

I am using the json2html package to convert JSON to HTML but I am getting the error - "fork/exec /home/sftp_user/uploads/json2html.py: exec format error"
以下是我所做的

    • 脚本如下所示**
#!/usr/bin/env python3
import sys
from json2html import *
from json import loads

ip = json.loads(sys.argv[1])
res = json2html.convert(json={"data":ip})
sys.stdout.write(res)
    • sys.argv [1]负载低于**
[ { "FirstName": "John", "LastName": "Doe", "StreetName": "120 jefferson st.", "County": "Riverside", "State": " NJ", "PostCode": 8075 }, { "FirstName": "Jack", "LastName": "McGinnis", "StreetName": "220 hobo Av.", "County": "Phila", "State": " PA", "PostCode": 9119 }, { "FirstName": "John \"Da Man\"", "LastName": "Repici", "StreetName": "120 Jefferson St.", "County": "Riverside", "State": " NJ", "PostCode": 8075 }, { "FirstName": "Stephen", "LastName": "Tyler", "StreetName": "7452 Terrace \"At the Plaza\" road", "County": "SomeTown", "State": "SD", "PostCode": 91234 }, { "FirstName": null, "LastName": "Blankman", "StreetName": null, "County": "SomeTown", "State": " SD", "PostCode": 298 }, { "FirstName": "Joan \"the bone\", Anne", "LastName": "Jet", "StreetName": "9th, at Terrace plc", "County": "Desert City", "State": "CO", "PostCode": 123 } ]
    • 错误**
fork/exec /home/sftp_user/uploads/json2html.py: exec format error

你知道代码中有什么问题吗?

rxztt3cl

rxztt3cl1#

您输入的JSON中的null值似乎有问题。请尝试先将其转换为None,然后就可以了

from json2html import *
data = [ { "FirstName": "John", "LastName": "Doe", "StreetName": "120 jefferson st.", "County": "Riverside", "State": " NJ", "PostCode": 8075 }, { "FirstName": "Jack", "LastName": "McGinnis", "StreetName": "220 hobo Av.", "County": "Phila", "State": " PA", "PostCode": 9119 }, { "FirstName": "John \"Da Man\"", "LastName": "Repici", "StreetName": "120 Jefferson St.", "County": "Riverside", "State": " NJ", "PostCode": 8075 }, { "FirstName": "Stephen", "LastName": "Tyler", "StreetName": "7452 Terrace \"At the Plaza\" road", "County": "SomeTown", "State": "SD", "PostCode": 91234 }, { "FirstName": None, "LastName": "Blankman", "StreetName": None, "County": "SomeTown", "State": " SD", "PostCode": 298 }, { "FirstName": "Joan \"the bone\", Anne", "LastName": "Jet", "StreetName": "9th, at Terrace plc", "County": "Desert City", "State": "CO", "PostCode": 123 } ]
res = json2html.convert(json={"data": data})
print(res)

输出:

<table border="1"><tr><th>data</th><td><table border="1"><thead><tr><th>FirstName</th><th>LastName</th><th>StreetName</th><th>County</th><th>State</th><th>PostCode</th></tr></thead><tbody><tr><td>John</td><td>Doe</td><td>120 jefferson st.</td><td>Riverside</td><td> NJ</td><td>8075</td></tr><tr><td>Jack</td><td>McGinnis</td><td>220 hobo Av.</td><td>Phila</td><td> PA</td><td>9119</td></tr><tr><td>John &quot;Da Man&quot;</td><td>Repici</td><td>120 Jefferson St.</td><td>Riverside</td><td> NJ</td><td>8075</td></tr><tr><td>Stephen</td><td>Tyler</td><td>7452 Terrace &quot;At the Plaza&quot; road</td><td>SomeTown</td><td>SD</td><td>91234</td></tr><tr><td>None</td><td>Blankman</td><td>None</td><td>SomeTown</td><td> SD</td><td>298</td></tr><tr><td>Joan &quot;the bone&quot;, Anne</td><td>Jet</td><td>9th, at Terrace plc</td><td>Desert City</td><td>CO</td><td>123</td></tr></tbody></table></td></tr></table>

tvmytwxo

tvmytwxo2#

经过数小时的故障排除,发现脚本文件名“json2html.py“导致了问题(与包名json2html冲突)。更改脚本文件名后,脚本开始工作。

相关问题