python - 为什么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)
我试图更改编码,但对我没有帮助。
解决方案
推荐阅读
- typescript - 将 Typescript 类 DTO 转换为 JSON Schema 用于 Fastify Swagger
- html - 如何在其兄弟元素悬停时访问伪元素
- python - 反转包含超过 2 个元素的元组
- plotly-dash - 如何在 dash-leaflet 中制作交互式世界地图?
- sql - PLSQL 中的标识符无效
- python - 我希望使用 lambda 和 pandas 使用 pythonic 方式优化代码
- html - 如何为谷歌网络应用程序脚本进行自动对焦?
- c# - 以编程方式更改数据网格中的列值
- r - r for 循环中的迭代
- android - 如何修复cardview在回收站视图中相互重叠?