python 将字符串转换成字典dict

yipeiwu_com6年前Python基础

复制代码 代码如下:

JSON到字典转化:
dictinfo = simplejson.loads(json_str) 输出dict类型

字典到JSON转化:
jsoninfo = simplejson.dumps(dict)输出str类型

比如:
info = {'name' : 'jay', 'sex' : 'male', 'age': 22}
jsoninfo = simplejson.dumps(info)
print jsoninfo
print type(jsoninfo)

    

相关文章

Python 词典(Dict) 加载与保存示例

Dict的加载: import json def load_dict(filename): '''load dict from json file''' with open(f...

django echarts饼图数据动态加载的实例

django echarts饼图数据动态加载的实例

如下所示: 后台关键代码: data = {} #keys与values分别为该数据的键数组,值的数组。这里循环为字典添加对应键值 for k, v in zip(keys, val...

python使用sorted函数对列表进行排序的方法

本文实例讲述了python使用sorted函数对列表进行排序的方法。分享给大家供大家参考。具体如下: python提供了sorted函数用于对列表进行排序,并且可以按照正序或者倒序进行排...

剖析Python的Tornado框架中session支持的实现代码

tornado 里面没有 session?不,当然有~我知道 github 上肯定有人帮我写好了~ O(∩_∩)O~       于是乎...

Python中用format函数格式化字符串的用法

自python2.6开始,新增了一种格式化字符串的函数str.format(),可谓威力十足。那么,他跟之前的%型格式化字符串相比,有什么优越的存在呢?让我们来揭开它羞答答的面纱。 语法...