【发布时间】:2020-10-09 05:30:54
【问题描述】:
我目前有一个脚本,它遍历 JSON 结果列表并为每个结果提取某些信息。我目前正在尝试为位于 animalURLS 列表中的每个结果提取标签。
如果我不添加if statement,循环将成功通过列表。但是,如果我要添加if statement,输出会发生变化,它只会遍历我拥有的整个结果列表的一部分。使用if statement,它将打印的最大项目数为 85。即使有适当的标签,也会有某些结果被遗漏。
以下是可能的标签列表:
- 猫
- 狗
- 鸟
- 其他
我不确定为什么我的代码无法获得某些结果,希望能提供任何帮助。
for i, v in enumerate(miskaJSON[str(ctx.guild.id)]["animalURLS"]):
if v[2] == tag:
print(v)
print(i)
这是 miskaJSONStructure 的一个示例,这是我的代码所基于的。标记是 animalURLS 列表中的最后一项:
"628704494615789599": {
"prefix": "%",
"animalURLS": [
[
"Darth Kylo-Kun",
"https://cdn.discordapp.com/attachments/628704495047671818/723325532397109329/IMG_20170531_140251.png",
"cat"
]
],
"tags": [
"cat",
"dog",
"bird",
"other"
]
}
【问题讨论】:
-
你能把miskaJSON结构放上去吗
-
请稍等
-
添加 json 结构
-
控制台中显示的任何错误?
标签: python python-3.x list discord.py