json - json 导入是否因为 JSON 文件而失败?
问题描述
我有一个简单的 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 文件中的错误。错误发生在您看到 None、True 或 False 值的任何地方。
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 程序读入的文件。
解决方案
推荐阅读
- javascript - 移动响应式下拉导航栏适用于小宽度浏览器,但不适用于我的手机
- regex - 不匹配某些字符串的正则表达式
- json - 替换 PostgreSQL 9.6 中的第一个和最后一个 JSON 字符
- javascript - 在元素中包裹 iframe
- amazon-web-services - 亚马逊网络服务上 Hyperledger Fabric 的最佳系统
- sql - 将 SQL Server 查询 2012 转换为 2008
- php - PHP Range function for creating steps between 2 dates
- android - 我希望当我按下 SongPlayingFragment 中的硬件后退按钮时,我应该返回主屏幕。我该怎么做?
- java - 将dll添加到jee maven项目
- c++ - C ++二进制搜索算法中的内存错误“*** `./Drivers'中的错误:free():下一个大小无效(正常):0x000000000166c2d0 ***”