在Python中使用空间解析Json数据

时间:2018-07-24 06:53:01

标签: python-3.x discord.py

我尝试加载JSON文件,但无法使用空间。

如果我尝试加载!ping Steve正常工作,!ping "George Stephen"正常工作,但是如果我尝试加载!ping George Stephen正常工作,则失败。

json文件示例

{"people": [
{"Name": "Steve", "Sex": "Male", "age": "30"},
{"Name": "Rachel", "Sex": "Female", "age": "25"},
{"Name": "George Stephen", "Sex": "Male", "age": "22"} ] }

@bot.command(pass_context=True)
async def ping(ctx, namesList):
  with open('data.json') as json_file:
    d = json.load(json_file)
    for p in d['people']:
      if(p['Name'] in (namesList)):
        await bot.send_message(ctx.message.channel, p)

0 个答案:

没有答案