[英]How to fix 'json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)' error?
Every time someone writes an error appears.每次有人写错误都会出现。 I hope I didn't make a usual mistake
我希望我没有犯一个通常的错误
Code:代码:
@client.event
async def on_message(message):
await client.process_commands( message )
with open('C:\\Ультилиты\\ProgramBotDiscord\\lvl.json', 'r' ) as f:
users = json.load(f)
async def update_data(users, user):
if not user in users:
users[user] = {}
users[user]['exp'] = 0
users[user]['lvl'] = 1
await update_data(users, message.author.id)
with open('C:\\Ультилиты\\ProgramBotDiscord\\lvl.json', 'w' ) as f:
json.dump(users, f)
Cmd: Cmd:
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Programs\lib\site-packages\discord\client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "501.py", line 319, in on_message
users = json.load(f)
File "C:\Programs\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Programs\lib\json\__init__.py", line 357, in loads
return _default_decoder.decode(s)
File "C:\Programs\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Programs\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
There would be your problem, for this to work you need data in your json file.会有您的问题,为此您需要 json 文件中的数据。 If you want you can have a system such as using the try: and except: to try to receive data and if failed, print out a message or something.
如果你愿意,你可以有一个系统,比如使用 try: 和 except: 来尝试接收数据,如果失败,打印出一条消息或其他东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.