xml文件解析:
使用xmltodict模块
安装xmltodict:
pip install xmltodict
直接上代码:
import xmltodict
import json
def parsing_request_xml_result(xml_files):
new_dict = xmltodict.parse(xml_files)
json_result = json.dumps(new_dict)
return json_result
new_dict 是个collections.OrderedDict 我没找到合适直接转为dict的方法 采用的json.dumps
json_result 是json数据
最终返回的是json数据