我有一个简单的python程序,该程序应将.json文件加载到变量中并将变量输出打印到屏幕上。但是它无法运行,并显示以下消息:
"File "/Documents/VSCode/python-3-programming-specialization/Data Collection and Processing with Python (Course 3)/Lesson 1/assessment6.py", line 5, in <module>
res = json.load(json_file,)
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 296, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/__init__.py", line 348, in loads
return _default_decoder.decode(s)
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/local/Cellar/python/3.7.2_1/Frameworks/Python.framework/Versions/3.7/lib/python3.7/json/decoder.py", line 355, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 15 column 25 (char 506)"
在JSON文件中也有一个我认为是问题的错误,但是我不知道要设置什么值来清除JSON文件中的错误。该错误会在您看到无,真或假值的任何地方发生。
JSON错误消息:“期望值json(516)
"statuses": [
{
"contributors": None,
"truncated": False,
"text": "RT @mikeweber25: I'm decommiting from the university of Michigan thank you Michigan for the love and support I'll remake my decision at the\u2026",
"in_reply_to_status_id": None,
"id": 536624519285583872,
"favorite_count": 0,
"source": "<a href=\"http://twitter.com/download/iphone\" rel=\"nofollow\">Twitter for iPhone</a>",
"retweeted": False,
"coordinates": None,
import json
with open('./tweets.json') as json_file:
res = json.load(json_file)
print(res)
预期输出应该是python程序读取的文件。