【发布时间】:2021-11-10 09:14:58
【问题描述】:
如何从 API 中提取元素 .. API 看起来像
{"response_code":0,"results":[{"category":"General Knowledge","type":"multiple","difficulty":"hard","question":"Electronic music producer Kygo's popularity skyrocketed after a certain remix. Which song did he remix?","correct_answer":"Ed Sheeran - I See Fire","incorrect_answers":["Marvin Gaye - Sexual Healing","Coldplay - Midnight","a-ha - Take On Me"]}]}
async with aiohttp.ClientSession() as session:
request = await session.get('https://opentdb.com/api.php?amount=1&category=9&difficulty=hard')
questionjson = await request.json()
request2 = await session.get('https://opentdb.com/api.php?amount=1&category=9&difficulty=hard')
questionjson1 = str(questionjson['results'])
embed = discord.Embed(title="**__Trivia Time !!__**",description = questionjson1['question'] ,color= random.choice(colors))```
And I only want to extract the “question” element from that api
【问题讨论】:
-
您能否展示一些代码或告诉我们您尝试了什么?
标签: json api discord.py