python string 转dict

来源:互联网 发布:大数据视频 百度云盘 编辑:程序博客网 时间:2024/05/30 23:03
# -*- coding: utf-8 -*-import astimport jsonstrjson = '{"host":"192.168.1.1", "port":3306}'# 方式一:  string 转 dictresjson = ast.literal_eval(strjson)print type(strjson)print type(resjson)# 方式二:  string 转 dictresjson2 = eval(strjson)print type(strjson)print type(resjson2)# 方式三:  string 转 dictresjson3 = json.loads(strjson)print type(strjson)print type(resjson3)
0 0
原创粉丝点击