加载json文件时遇到问题

2024-09-28 01:22:44 发布

您现在位置:Python中文网/ 问答频道 /正文

今天编程我的机器人我需要做的命令,将编辑json文件的公会设置

但出于某种原因,我犯了一个错误

Command raised an exception: TypeError: Object of type TextIOWrapper is not JSON serializable

我所做的就是这样

    with open('database.json') as file:
         loadedFile = json.load(file)

    for checkingGuild in loadedFile["guilds"]:
        if int(checkingGuild["guild-id"]) == ctx.guild.id:
            guild = checkingGuild
            break

    guild["global-group-id"] = int(ID)

    with open('database.json','w') as f:
        json.dump(loadedFile,f, indent=4)

这个json.load(文件)正在解决这个问题,但我不知道为什么!当我加入公会的时候,这件事很好,但出于某种原因,这件事正在发生! 请回答,如果你知道如何修复它


Tags: 文件idjsonas编程withloadopen

热门问题