首页 > 解决方案 > json.decoder.JSONDecodeError:期望值:第 1 行第 18 列(字符 17),未发现任何故障

问题描述

也许你比我更了解那些解码错误,但我得到了这个错误:

Ignoring exception in on_message
Traceback (most recent call last):
  File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\lib\site-packages\discord\client.py", line 333, in _run_event
    await coro(*args, **kwargs)
  File "C:\Users\FlexGames\Desktop\Programming\Discord Bot\New Bot\main.commands.py", line 91, in on_message
    await XPRole.save_last_msg(fb)
  File "C:\Users\FlexGames\Desktop\Programming\Discord Bot\New Bot\New_Functions\XPRole.py", line 59, in save_last_msg
    jsonhandle.update("last_message", lastmsg, "lastmsg")
  File "C:\Users\FlexGames\Desktop\Programming\Discord Bot\New Bot\Functions\jsonhandle.py", line 56, in update
    _load(jsonfile)
  File "C:\Users\FlexGames\Desktop\Programming\Discord Bot\New Bot\Functions\jsonhandle.py", line 73, in _load
    lmsgjson = json.load(lmsgload)
  File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\lib\json\__init__.py", line 346, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Try Me Btch\AppData\Local\Programs\Python\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 18 (char 17)

我的错误代码是:

elif jsonfile == "lastmsg":
    global lmsgjson
    with open("C:/Users/FlexGames/Desktop/Programming/Discord Bot/New Bot/lastmsg.json", "r") as lmsgload:
        lmsgjson = json.load(lmsgload)

我不知道它可能是什么,因为我也试图删除完整的路径,所以只使用“lastmsg.json”,但我得到了同样的错误。

标签: pythonjson

解决方案


解决方案:

你不能像

{"whatever": }

推荐阅读