问题描述:
lottery_url = 'http://********************'
req = req_session.post(lottery_url, data={'usernumberofjsp': encryptmobile}, timeout=30)
lottery_message = req.json()
print(lottery_message)
结果输出
{u'RspMsg': u'\u7528\u6237\u673a\u4f1a\u6b21\u6570\u4e0d\u8db3', u'Rsptype': u'6666'}
##中文显示为乱码\u7528\u6237\u673a\u4f1a\u6b21\u6570\u4e0d\u8db3
输出中文依然为unicode编码
原因:
json解析中文会默认使用的ascii编码。
解决办法:
指定ensure_ascii=False
lottery_url = 'http://m.client.10010.com/dailylottery/static/doubleball/choujiang'
req = req_session.post(lottery_url, data={'usernumberofjsp': encryptmobile}, timeout=30)
#lottery_message = req.json()
lottery_message=json.dumps(req.json(), ensure_ascii=False)
print(lottery_message)
{"RspMsg": "用户机会次数不足", "Rsptype": "6666"}