0

我想计算结果 JSON 对象的数量:我该怎么办?

我有这个功能:(问题出在“for i in r:”)

import urllib
import json
from classes import ricerca_IMDB

def search_IMDB (titolo):
    sito='http://www.omdbapi.com/?s='+titolo

    r=0
    r=json.loads(urllib.urlopen(sito).read())

    i=0
    filmList = []
    try:
        for i in r:
            filmList.append(ricerca_IMDB(r['Search'][i]['Title'], r['Search'][i]['Year'], r['Search'][i]['imdbID']))
    except:
        filmList = []

    return filmList
4

1 回答 1

2

你已经完全搞砸了你的类型处理。迭代一个序列会产生元素

for i in r['Search']:
  filmList.append(ricerca_IMDB(i['Title'], i['Year'], i['imdbID']))
于 2012-12-11T22:03:13.083 回答