我有一个XML文件,我想使用python转换为JSON文件,但它正在为我工作.
<?xml version="1.0"?>
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Run Code Online (Sandbox Code Playgroud)
上面的XML文件我正在使用ElementTree进行解析并将其提供给Simplejson以进行序列化,如下所示:
from xml.etree import ElementTree as ET
import simplejson
tree = ET.parse(Xml_file_path)
simplejson.dumps(tree)
Run Code Online (Sandbox Code Playgroud)
它给出了一个错误:TypeError:0x00C49DD0处的xml.etree.ElementTree.ElementTree对象不是JSON可序列化的.