python报错json.decoder.JSONDecodeError

源代码

import json, os, sys

path_name = 'f:/python/apple.json'
print("What's your name?\n)

with open(path_name,'r') as f:
    hyp = json.load(f)

while True:
    username = input()
    if username == 'exit':
        break
    if int(username) in hyp:
        print(f"welcome back!{username.title()}")
    else:
        with open(path_name,'a') as p:
            json.dump(username,p)

apple.json

"gg""hello""lower"

报错

Traceback (most recent call last):
  File "e:\python\gg.py", line 5, in <module>
    hyp = json.load(p)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\lib\json\decoder.py", line 337, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "C:\Users\Administrator\AppData\Local\Programs\Python\Python38\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 2 (char 1)

望大佬指点

你apple.json的数据格式不是json 格式,json格式类似python的字典,你将apple.json的文件内容改为{'gg': 'gg','hello':'hello'}试试

如果对你有帮助,可以点击我这个回答右上方的【采纳】按钮,给我个采纳吗,谢谢

"gg""hello""lower" 这个不是json格式。。

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632