python xml_str转json

使用第三方模块xmltodict

pip3 install xmltodict

使用:

import xmltodict

def xmlToJson(xml_str):
    '''传入xml字符串,返回字典'''
    dic = xmltodict.parse(xml_str, encoding='utf-8')
    return dic

 

posted on 2021-11-16 18:02  longfei2021  阅读(118)  评论(0编辑  收藏  举报