使用Python实现Xml到Json的转换

XML 到 JSON 文件转换器

import json         #导入json库
import xmltodict    #导入 xmltodict

with open('input.xml') as xml_file:
    parser_data = xmltodict.parse(xml_file.read())        # xmltodict.parse()方法可以将xml数据转为python中的dict字典数据:
    xml_file.close()

    json_conversion = json.dumps(parser_data)       #   将python对象编码成Json字符串

    with open('output.json','w') as json_file:
        json_file.write(json_conversion)        #写入文件
        json_file.close()

参考:https://github.com/Python-World/python-mini-projects

你可能感兴趣的:(Python,python)