简体   繁体   English

如何修复 'json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)' 错误?

[英]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.

相关问题 json.decoder.JSONDecodeError:期望值:第2行第1列(char 1)错误 - json.decoder.JSONDecodeError: Expecting value: line 2 column 1 (char 1) error 错误:json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - ERROR: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 如何修复 json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)? - How can fix json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)? 奇怪的“json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)” - WEIRD "json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)" json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) ##json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)## - ##json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)## json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0)Scrapy - json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) Scrapy 什么是json.decoder.JSONDecodeError:期望值:第1行第1列(字符0) - What is json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 随机 json.decoder.JSONDecodeError:期望值:第 1 行第 1 列(字符 0) - Random json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0) 遇到:json.decoder.JSONDecodeError:预期值:第1行第1列(字符0) - Encounter: json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM