首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

Python xml、字典、json、类四种数据类型如何实现互相转换

等库去解析xml文件为Python的数据类型再去操作,比较繁琐,如今在写Django网站ajax操作时json的解析,发现这篇帖子对这几种数据类型的转换操作提供了另一种更简洁的方法,xmltodict和 dicttoxml...模块,方法:dicttoxml.dicttoxml(字典数据,根节点名称 custom_root=”)import dicttoxml from xml.dom.minidom import parseString...{'name': 'pear', 'num': 20, 'price': 18.7}, {'name': 'banana', 'num': 10.5, 'price': 23}] bxml=dicttoxml.dicttoxml...转换为字典 import json import dicttoxml f=open('products.json','r',encoding='utf-8') jsonstr=f.read() # 将...json转换为字典 d=json.loads(jsonstr) print(d) # 将字典转换为xml bxml=dicttoxml.dicttoxml(d,custom_root='fruit')

3.3K10
  • 您找到你想要的搜索结果了吗?
    是的
    没有找到

    扫码

    添加站长 进交流群

    领取专属 10元无门槛券

    手把手带您无忧上云

    扫码加入开发者社群

    热门标签

    活动推荐

      运营活动

      活动名称
      广告关闭
      领券