【发布时间】:2018-10-05 09:04:15
【问题描述】:
我有一个格式如下的 XML 文件 -
<root>
<tag>
This is the first Value.
</tag>
<tag>
This is the second Value.
</tag>
</root>
当我使用以下代码在 Python 中将此 XML 字符串转换为 JSON 时
jsonString=json.dumps(XML_String)
标签变成数组,我得到的JSON文件是这样的——
{"root":["tag":"This is the first Value",
"tag":"This is the second Value"]}
我真正想要的是<root> 标签应该是一个对象而不是一个数组。像这样——
{"root":{"tag":"This is the first Value",
"tag":"This is the second Value"}}
如何实现这种格式?
【问题讨论】:
标签: python json xml mongodb parsing