|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
username.json文件只有一个值使用json.load()程序可以正常运行,但是username.json有多个值就报错
报错信息:
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 1 column 15 (char 14)
源码:
import json
def my_greet_user():
filename = 'username.json'
try:
input_name = input('你叫什么名字!\n')
with open(filename) as f:
username = json.load(f)
except FileNotFoundError:
print('新用户你好!欢迎你加入我们')
username = input_name
with open(filename,'w') as f:
json.dump(username,f)
print('你提供的名字已记录!')
else:
if input_name != username:
with open(filename, 'w') as f:
json.dump(input_name, f)
print('你好'+input_name+'!')
print('你已经成为我们的一员!')
else:
print(input_name+'你好!欢迎你回来!')
my_greet_user() |
|