【发布时间】:2019-12-19 06:36:53
【问题描述】:
我正在尝试使用 xmltodict 库在 python 中将 xml 转换为 json。虽然,xml 正在转换为 json,但在 dict 中的每个键之前,'@' 都会被添加前缀。下面是代码 sn-p 和示例输出:
import xmltodict
import json
with open('response.xml','r') as res_file:
doc = xmltodict.parse(res_file.read())
xml_json_str = json.dumps(doc)
final_json = json.loads(xml_json_str)
输出:
"CustomerInfo": {
"@address": "Bangalore, Karnataka 560034",
"@email": "abc@gmail.com",
"@name": "Sam",
}
如何一次性从所有键中删除@?
【问题讨论】:
-
你能显示xml文件的内容吗?
-
@Solen'ya:下面是 xml 内容。 google.com">
标签: python python-3.x xmltodict xml-to-json