首页 > 解决方案 > 为什么json文件没有在我的程序中打开?

问题描述

我的程序中有一个学校时间表,当我使用

import json


if choice == "Schedule":
    with open("Schedule.json", "r") as schedule_file:
        schedule_output = json.load(schedule_file)
        schedule_choice = input('\nDo you want to exit or change the schedule?\n')

问题来了:

Traceback (most recent call last):
File "practice.py", line 92, in <module>
    schedule_output = json.load(schedule_file)
  File "C:\Users\Samwise\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 293, in load
    return loads(fp.read(),
  File "C:\Users\Samwise\AppData\Local\Programs\Python\Python38\lib\json\__init__.py", line 357, in loads
    return _default_decoder.decode(s)
  File "C:\Users\Samwise\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\Samwise\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 1 (char 0)

我试图更改编码,但对我没有帮助。

标签: pythonjson

解决方案


推荐阅读