私はTwitter検索APIを使用して作業しており、Pythonを使用して戻ってくるデータを解析しています。私はpython-noobなので、行き詰まっていますが、私のエラーはおそらく私の理解不足です。
私の応答は次のようになります。
そして私のコード; 「responseJson」は、APIをヒットせずにテストを継続するために、Twitterからの応答を保存したファイルです。
responseJson = json.loads(open(DEBUG_JSON).read())
for key, value in responseJson.iteritems():
if key == 'results':
print "type: ", type(value)
for tweetKey, tweetValue in value.iteritems():
print tweetKey
プログラムを実行すると、次のようになります。
$ python search.py
type: <type 'list'> <-- says it's a list!
Traceback (most recent call last):
File "search.py", line 46, in <module>
for tweetKey, tweetValue in value.iteritems():
AttributeError: 'list' object has no attribute 'items'
「value」はリストであるという出力が表示されます。これは、iteritems()を呼び出すことができるはずであることを意味します。私はいつも「responseJsonでiteritems()を呼び出します。
どんな助け/明快さもありがたいです、TIA!