python string to dict

Posted by Jeffery Yee | 12:58 PM

python string (json format) to dict

JSON to Python dict

dictinfo = simplejson.loads(json_str)  # output as a dict type

python dict to JSON: 

jsoninfo = simplejson.dumps(dict) ## output as a string type

Examples: 

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

PS: another tip is that you can use eval, try eval(json_str), which will return a python dict type.

0 comments

Popular Posts

无觅相关文章插件,迅速提升网站流量