当前位置:优学网  >  在线题库

使用Python将信息写入JSON文件时额外[]

发表时间:2022-07-19 01:07:52 阅读:84

当我在JSON文件中写入一些内容时,它会在内容前面添加一些额外的[],这会使JSON文件崩溃.这是我的代码:

newuser =   {
             "id": message.author.id,
             "num": 0
             },
json.dump(newuser, l,  indent=4, separators=(',',': '), ensure_ascii=False)

这是我的JSON文件:

[
    {
        "id": 1,
        "num": 11
    },
    {
        "id": 2,
        "num": 22
    }
][
    {
        "id": 335847688702787585,
        "num": 0
    }
]

正如我所说,额外的[]正在破坏整个文件

🎖️ 优质答案
相关问题