为了账号安全,请及时绑定邮箱和手机立即绑定

python中,unicode对象怎么转换成dict?

python中,unicode对象怎么转换成dict?

LNYIE 2018-02-05 22:22:06
result = {"count":4,"sub_images":[{"url":"http://p3.pstatp.com/origin/5e8800034ace2b572928","width":690,"url_list":[{"url":"http://p3.pstatp.com/origin/5e8800034ace2b572928"},{"url":"http://pb9.pstatp.com/origin/5e8800034ace2b572928"},{"url":"http://pb1.pstatp.com/origin/5e8800034ace2b572928"}],"uri":"origin/5e8800034ace2b572928","height":1003},{"url":"http://p1.pstatp.com/origin/6158000163084595c6fb","width":690,"url_list":[{"url":"http://p1.pstatp.com/origin/6158000163084595c6fb"},{"url":"http://pb3.pstatp.com/origin/6158000163084595c6fb"},{"url":"http://pb9.pstatp.com/origin/6158000163084595c6fb"}],"uri":"origin/6158000163084595c6fb","height":975},{"url":"http://p3.pstatp.com/origin/5e820003c5d5ac717d18","width":690,"url_list":[{"url":"http://p3.pstatp.com/origin/5e820003c5d5ac717d18"},{"url":"http://pb9.pstatp.com/origin/5e820003c5d5ac717d18"},{"url":"http://pb1.pstatp.com/origin/5e820003c5d5ac717d18"}],"uri":"origin/5e820003c5d5ac717d18","height":1035},{"url":"http://p3.pstatp.com/origin/6158000163329ce51ec3","width":690,"url_list":[{"url":"http://p3.pstatp.com/origin/6158000163329ce51ec3"},{"url":"http://pb9.pstatp.com/origin/6158000163329ce51ec3"},{"url":"http://pb1.pstatp.com/origin/6158000163329ce51ec3"}],"uri":"origin/6158000163329ce51ec3","height":1035}],"max_img_width":690,"labels":["u738bu5b50u6587","Burberry","u65f6u88c5u642du914d"],"sub_abstracts":["u738bu5b50u6587u66ddu5149u6700u65b0u673au573au8857u62cduff0cu6df1u84ddu8272Burberryu5916u5957u642du914dStuart Weitzmanu9ed1u8272u957fu9774uff0cu7b80u6d01u5e05u6c14u3002u8fd9u4e48u4e45u7684u745cu4f3du679cu7136u4e0du662fu767du7ec3u7684uff0cu201cu66f2u5996u7cbeu201du9a7eu9a6du670du88c5u7684u80fdu529bu597du50cfu8d8au6765u8d8au5f3au4e86u3002"," "," "," "],"sub_titles":["u738bu5b50u6587u66ddu5149u6700u65b0u673au573au8857u62cduff0cu6df1u84ddu8272u5916u5957u642du914du9ed1u8272u957fu9774","u738bu5b50u6587u66ddu5149u6700u65b0u673au573au8857u62cduff0cu6df1u84ddu8272u5916u5957u642du914du9ed1u8272u957fu9774","u738bu5b50u6587u66ddu5149u6700u65b0u673au573au8857u62cduff0cu6df1u84ddu8272u5916u5957u642du914du9ed1u8272u957fu9774","u738bu5b50u6587u66ddu5149u6700u65b0u673au573au8857u62cduff0cu6df1u84ddu8272u5916u5957u642du914du9ed1u8272u957fu9774"]}以上result,是我在网页中获取到的,但是print type(result)显示该对象为unicode,不是dict请问怎么样能转换成dict?
查看完整描述

2 回答

?
慕码人5092043

TA贡献13条经验 获得超1个赞

result = result.encode('utf-8')  #将unicode转换成string

jd = json.loads(result)   #将string转换成dict

[如有雷同,纯属抄袭]

查看完整回答
反对 回复 2018-02-06
?
LNYIE

TA贡献5条经验 获得超0个赞

自问自答,

result = result.encode('utf-8')  #将unicode转换成string

jd = json.loads(result)   #将string转换成dict



查看完整回答
反对 回复 2018-02-05
  • 2 回答
  • 0 关注
  • 7717 浏览
慕课专栏
更多

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信