python如何提取接口返回的data里面的数据?

3131975015
  • 411

print(json.loads(r.content))打印结果是下面的内容
可是我想要data里面的某些字段的信息 请问怎么取呢?

{"ok":1,"data":{"cardlistInfo":{"containerid":"1076035541210428","v_p":42,"show_style":1,"total":5164,"page":4},"cards":[{"card_type":9,"itemid":"1076035541210428_-_4403110468243397","scheme":"https:\/\/m.weibo.cn\/status\/I1iUSyAu1?mblogid=I1iUSyAu1&luicode=10000011&lfid=1076035541210428","mblog":{"visible":{"type":0,"list_id":0},"created_at":"08-08","id":"4403110468243397","idstr":"4403110468243397","mid":"4403110468243397","can_edit":false,"show_additional_indication":0,"text":"\u54c8\u54c8\u54c8\u54c8\u54c8\uff0c\u592a\u96be\u4e86\uff01<span class=\"url-icon\"><img alt=[\u5141\u60b2] src=\"\/\/h5.sinaimg.cn\/m\/emoticon\/icon\/default\/d_yunbei-9aa3c436a4.png\" style=\"width:1em; height:1em;\" \/><\/span><span class=\"url-icon\"><img alt=[\u5141\u60b2] src=\"\/\/h5.sinaimg.cn\/m\/emoticon\/icon\/default\/d_yunbei-9aa3c436a4.png\" style=\"width:1em; height:1em;\" \/><\/span><a  href=\"https:\/\/m.weibo.cn\/search?containerid=231522type%3D1%26t%3D10%26q%3D%23%E5%93%88%E5%A3%AB%E5%A5%87%E6%90%9E%E7%AC%91%E8%A7%86%E9%A2%91%23&isnewpage=1&luicode=10000011&lfid=1076035541210428\" data-hide=\"\"><span class=\"surl-text\">#\u54c8\u58eb\u5947\u641e\u7b11\u89c6\u9891#<\/span><\/a> <a data-url=\"http:\/\/t.cn\/AiTJsZxT\" href=\"https:\/\/m.weibo.cn\/p\/index?containerid=2304444400830749808040&url_type=39&object_type=video&pos=1&luicode=10000011&lfid=1076035541210428\" 
回复
阅读 5.5k
2 个回答
✓ 已被采纳

如果是 requests 模块发起请求

import requests

result = requests.get('xx')
# result.json() 就是json 对象
if result.status_code == 200:
    print(result.json().get('data'))

https://www.runoob.com/python...

json.loads 不就是把json字符串变成python的map吗

>>> a = '{"a":12}'
>>> js = json.loads(a)
>>> js["a"]
12

你是什么意思?

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
宣传栏