我正在使用以下脚本:
tagRequest = requests.get("https://api.instagram.com/v1/tags/" + tag + "/media/recent?client_id=" + clientId)
tagData = json.loads(tagRequest.text)
tagId = tagData["data"][0]["user"]["id"]
for i in tagData["data"]:
print tagData["data"][i]
我的脚本应该遍历JSON对象tagData。(Over everything in "data".) However, I am getting the following error:
list indices must be integers, not dict.
最佳答案
You are iterating over the contents of tagData['data']
not its indices, so:
for i in tagData["data"]:
print i
或索引:
for i in xrange(len(tagData["data"])):
print tagData["data"][i]