我正在发送一个 URL 作为请求,作为响应,我得到了一个字典列表,我无法遍历这些值。
def profile_model(request):
response = unirest.get(url,header)
#url and header is defined outside the function
contents = response.raw_body
for i in contents:
print i['items']
print i['profiles']
return render(request,"profile_model.html",{})
在调试模式下,我看到
Name:contents
Value:
str: {
"items" : [ 13184519, 13184195, 13183948, 13184350, 13183946, 13184208],
"profiles" : [ "slezyr", "stefek99", "amlib", "vyrotek", "xenophonf", "TheGrumpyBrit"]
}
我收到 TypeError:字符串索引必须是整数,而不是 str。如果我删除项目中的引号,我将得到未定义的变量“项目”