Home >Backend Development >Python Tutorial >python 将字符串转换成字典dict

python 将字符串转换成字典dict

WBOY
WBOYOriginal
2016-06-16 08:46:341928browse

复制代码 代码如下:

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)

    

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn