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"]
窈窕包包,君子好逑