IT博客汇
  • 首页
  • 精华
  • 技术
  • 设计
  • 资讯
  • 扯淡
  • 权利声明
  • 登录 注册

    将 Json 转换为 Python Object(一)

    Yiran\'s Blog发表于 2018-06-09 11:43:49
    love 0
    $ cat example.py import json class JSONObject: def __init__(self, dict): vars(self).update(dict) # this is valid json string data = '{"channel":{"lastBuild":"2013-11-12", "component":["test1", "test2"]}}' jsonobject = json.loads(data, object_hook=JSONObject) print(jsonobject.channel.component[0]) print(jsonobject.channel.lastBuild) $ python example.py test1 2013-11-12


沪ICP备19023445号-2号
友情链接