首页 > Python中Unicode如何转换为字典?

Python中Unicode如何转换为字典?

爬虫得到的数据为:

{"params": {"topic_id": 253, "offset": 0, "hash_id": "3e5b6fac75c6362a9bc2ed3cb5bb3473"}, "nodename": "TopicsPlazzaListV2"}
 <type 'unicode'>

查看了一下type为unicode,现在怎么通过字典的方式获取?单个字段的值?比如topic_id:253


可以用json.loads(),你搜搜看


import json
str = '{"params": {"topic_id": 253, "offset": 0, "hash_id": "3e5b6fac75c6362a9bc2ed3cb5bb3473"}, "nodename": "TopicsPlazzaListV2"}'
param = json.loads(str)
print param['params']['topic_id']
【热门文章】
【热门文章】