【发布时间】:2019-09-12 09:00:12
【问题描述】:
我在迭代 Json 文件时遇到此错误 'NoneType' object is not iterable。
我的代码:
import nltk
import json
from nltk import word_tokenize
with open('full_format_recipes.json', 'r') as myfile:
data=myfile.read()
obj = json.loads(data)
result=[]
for a in obj:
for b in a.get("ingredients"):
print(type(b))
text = word_tokenize(b)
res = nltk.pos_tag(text)
res = [t for t in res if isinstance(t[1],list) not in ["NN",
"NNS","NNP", "NNPS"]]
print(res)
result.append(res)
错误:
for b in a.get("ingredients"): TypeError: 'NoneType' object is not iterable
【问题讨论】:
-
所以很可能没有关键的“成分”,因此出现错误,您检查了吗?
-
你能在这里解释/粘贴文件内容吗?