【发布时间】:2020-02-07 08:02:58
【问题描述】:
我一直在尝试显示 JSON 文件中的 cmets 列表。 我不断收到此错误:
Traceback(最近一次调用最后一次): 文件“JsonExtraction.py”,第 7 行,在 在 len(data) 中发表评论: TypeError: 'int' 对象不可迭代
我的代码如下所示:
import json
data = []
for line in open('rating_company_small.json', 'r'):
data.append(json.loads(line))
for comment in len(data):
print(comment['comment'])
谁能解释这个错误?
【问题讨论】:
-
你能在你的 rating_company_small.json 中分享一个示例数据(数据格式)吗?