我试图制作一些程序来告诉我在某个时间和某一天我上了什么课。 为了让它工作,我把我的日程安排放在一个json文件中(数字对应于天数)
{
"1": [
"french",
"french",
"yearit",
"geography",
"hebrew",
"shelah",
"science",
""
],
"2": [
"sports",
"literature",
"math rotem",
"geography",
"hebrew",
"hebrew",
"science",
"yearit"
],
"3": [
"yearit",
"english",
"math gila",
"english",
"yizhak",
"yizhak",
"",
""
],
"4": [
"english",
"math gila",
"science",
"math rotem",
"sports",
"literature",
"science",
"science"
],
"5": [
"life skills",
"yizhak",
"french",
"yizhak",
"math gila",
"italian",
"italian",
"math gila"
],
"6": [
"yizhak",
"english",
"english",
"math gila",
"science",
"",
"",
""
],
"7": [
"",
"",
"",
"",
"",
"",
"",
"",
],
}
我使用以下代码将其转换为python字典:
import json
with open('schedule.json', 'r') as f:
schedule = json.load(f)
print(schedule)
但它给了我这个错误信息:
Traceback (most recent call last):
File "C:\Users\user\Desktop\everything\coding lol\Python\CheckZoom\test.py", line 3, in <module>
schedule = json.load(f)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 293, in load
return loads(fp.read(),
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\json\__init__.py", line 346, in loads
return _default_decoder.decode(s)
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "C:\Users\user\AppData\Local\Programs\Python\Python39\lib\json\decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 71 column 2 (char 721)
如何解决此错误?谢谢你的帮助
正如@buran所指出的,文件末尾有额外的逗号,具体如下:
但是仍然可以使用^{} method 处理该文件:
印刷品:
分享一个单线风格的例子
相关问题 更多 >
编程相关推荐