Python3-Xml转Json
2021-04-11 02:28
标签:port 符号 不能 read json pen with open amp pytho Python3-Xml转Json 标签:port 符号 不能 read json pen with open amp pytho 原文地址:https://www.cnblogs.com/yunsongfu/p/13362480.htmlsuite>
case id="Demo.TestCase.001">
name>DemoTestCase001name>
path>testCase/demo/path>
case>
case id="Demo.TestCase.002">
name>DemoTestCase002name>
path>testCase/demo/path>
case>
suite>
import xmltodict
import json
with open(‘setInfo.xml‘, ‘r‘) as f:
str_xml = str(f.read())
print(str_xml)
str_xml = str_xml.replace(‘&‘, ‘&‘) # xml格式不能有"&"符号
doc = json.dumps(xmltodict.parse(str_xml))
print(doc)
dic = json.loads(doc)
print(dic)