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

python 将字符串转换成字典dict

WBOY
Release: 2016-06-16 08:46:34
Original
1923 people have browsed it

复制代码 代码如下:

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)

    

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template