python中处理json中遇到的错误(2020年2月25日17:44:42)更新中…
一、AttributeError: ‘list’ object has no attribute ‘get’

这里的主要问题在这里,就是“hotComments”下级是列表,列表无法直接get,应该替换为
content1 = text_json.get("hotComments").get('content')
替换为:
content1 = text_json.get("hotComments")[0].get('content') #获取列表中第一个字典里边的的'content'
或者:
for i in content1:
i.get('content')
本文解决Python处理JSON数据时常见的AttributeError问题,详细说明了如何正确访问列表内的字典元素,避免‘list’object has no attribute ‘get’错误。
5808

被折叠的 条评论
为什么被折叠?



