您的位置:首页 > 编程语言 > Python开发

python requests返回的json对象用json.loads()时转为字典时编码变为了unicode

2017-02-16 00:00 232 查看
1.使用simplejson,loads的对象为str,否则还是会转码unicode

import simplejson
url = ""
payload = {}
headers = {}
r = requests.post(url, data=payload, headers=headers)

result = simplejson.loads(str(r.text))
result2 = simplejson.loads(r._content)

2.使用eval(r.text)

eval涉及安全问题,会直接把字符串当编码执行,除非特定情况,不建议使用。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  json unicode python