首页 > 解决方案 > 尝试在 Python 中打开 JSON 文件时出现 JSONDecodeError

问题描述

我从Twitter 上抓取内容获得了以下 JSON 文件:

{"id": 911265668921733120, 
"conversation_id": "911265668921733120",
"created_at": "2017-09-22 19:27:20 EAT", 
"date": "2017-09-22",
"time": "19:27:20",
"timezone": "+0300", 
"user_id": 61177265, 
"username": "sircalic", 
"name": "Dan",
"place": {"type": "Point", 
"coordinates": [-1.18998912, 36.77644171]},
"tweet": "Bitcoin ain't stabilizing at $4,500 any time soon LOL but it's good to stock for long term.", 
"language": "en", 
"mentions": [],
"urls": [], 
"photos": [],
"replies_count": 0,
"retweets_count": 0,
"likes_count": 0,
"hashtags": [],
"cashtags": [],
"link": "https://twitter.com/sircalic/status/911265668921733120",
"retweet": false,
"quote_url": "",
"video": 0,
"thumbnail": "",
"near": "Nairobi", 
"geo": "", 
"source": "",
"user_rt_id": "",
"user_rt": "",
"retweet_id": "",
"reply_to": [],
"retweet_date": "", 
"translate": "", 
"trans_src": "",
"trans_dest": ""
}

但是当我尝试使用以下代码在 Python 中打开它时:

current_file = str(os.getcwd()) + '/NewYork2017-09-30 00:00:00.json'
l = json.load(open(current_file))

我收到以下错误:

JSONDecodeError: Extra data: line 2 column 1 (char 1036)

我已经对该错误进行了一些研究,并且不断收到错误消息,即字符有问题,但我似乎找不到解决方案。

有什么可以解决的吗?

标签: pythonjson

解决方案


推荐阅读