如何使用 Python 搜索具有给定参数的 JSON 文件?

How can I search a JSON file with given argument with Python?

我目前正在为 discord.py 机器人创建一个“信息 [参数]”命令,它将搜索 return 一个值

所以用户会说:“!Info bookshelf” 机器人会在 JSON 文件中查找“书架”并找到 bookshelf = Shelf full of books 并提取描述书架的值并在聊天中发送它。

我是编码新手,所以这很有帮助!提前谢谢你<3

致力于 Python 3.9

非常简单的解决方案:您只需从命令中获取参数(在本例中为“书柜”),然后将其解析为搜索。

def lookup(args):
    look = data[args]
    return look