python 接口测试字符类型转换

接口返回数据:

print sql[0][10]

{"recv_name":"rdgztest_63126","send_name":"rdgztest_63126","recv_avatar":"https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJ2bWib0TF1ppuFHlbN2W1tcoy68o0MJGkOrSke6uBibHTnSI3a8DsEWW6icJ5Vu0OLN8wPWEfHRDe1w/132","send_avatar":"https://wx.qlogo.cn/mmopen/vi_32/Q0j4TwGTfTJ2bWib0TF1ppuFHlbN2W1tcoy68o0MJGkOrSke6uBibHTnSI3a8DsEWW6icJ5Vu0OLN8wPWEfHRDe1w/132","blessing_msg":"118默认祝福语"}

   a = sql[0][10]

print type(a)
#输出为“Unicode”类型,转换为“str”类型
str1 = a.encode('utf-8')
print type(str1)
#“str”转换为“dict”
dict = json.loads(str1)
print type(dict)
#“dict”取值
print dict["recv_name"]
posted @ 2018-08-03 11:22  菜菜_包包  阅读(236)  评论(0编辑  收藏  举报