import json import xmltodict def xml_to_dict(xml_data): return xmltodict.parse(xml_data, attr_prefix='') if __name__ == '__main__': xml_str = """ TUOWEI668CBE9A6BCF4ABB121451181911|||mx14157184548492026-02-17933616502329:8@@CP0000008702@(院线)W+会员价活动2026@CP000000870281.92102026021612014408383211080581$68260216120144043666820325500131340PINGGUOPAY81.9000.01_1N1E8490000003590481843.0PINGGUOPAY-3.00-2102026021612014408383211080581-682602161201440436668000.03.0 """ print(json.dumps(xml_to_dict(xml_str), indent=4, ensure_ascii=False))