Possible Duplicate:
Converting XML to JSON using Python?
我正在导入一个XML提要,并尝试将其转换为JSON进行输出。我得到了这个错误:
TypeError: <xml.dom.minidom.Document instance at 0x72787d8> is not JSON serializable
不幸的是,我对Python几乎一无所知。我正在谷歌应用引擎上开发这个。我需要一些帮助,因为我的2小时的小黑客程序进行得很顺利,现在已经是第三天了。在
XML数据:
<?xml version="1.0" ?><eveapi version="2">
<currentTime>2009-01-25 15:03:27</currentTime>
<result>
<rowset columns="name,characterID,corporationName,corporationID" key="characterID" name="characters">
<row characterID="999999" corporationID="999999" corporationName="filler data" name="someName"/>
</rowset>
</result>
<cachedUntil>2009-01-25 15:04:55</cachedUntil>
</eveapi>
我的代码:
^{pr2}$
这个问题的态度无助于从这些Python用户那里得到答案。在
正如对this related question的回答中所提到的,XML和JSON之间没有1对1的对应关系,因此转换不能自动完成。在
在the documentation for ^{} 中,您可以找到它能够序列化的类型列表,这些类型基本上是本机Python类型(dict、list、unicode、int、float、True/False、None)。在
因此,您必须创建一个只包含这些类型的Python数据结构,然后将其交给
simplejson.dump()
。在相关问题 更多 >
编程相关推荐