迭代通过JSON
results
有时会变得相当混乱。 说我有一个function
像这样:python ::遍历嵌套的JSON结果
def get_playlist_owner_ids(query):
results = sp.search(q=query, type='playlist')
id_ = results['playlists']['items'][0]['owner']['id']
return (id_)
我可以获取id_
,它的工作原理。
但我如何迭代使用for i in x
循环,所以我return
ALL ids_
?
所有这些'id's的?你需要向我们展示你的'结果'数据结构的结构(以及你想要'id'值的级别或级别),以便为此负责。也许你想在结果['playlists'] ['items']]'中为[x ['owner'] ['id']],但这只是一个猜测。 – Blckknght