我尝试使用的代码如下:
import json
json_file = 'stream.txt'
open_file = open(json_file, "r")
for line in open_file:
each_tweet = json.loads(line.strip())
if 'text' in each_tweet:
print(each_tweet['id'])
print(each_tweet['text'])
hashtags = []
for tag in each_tweet['entities']['hashtags']:
hashtags.append(tag['text'])
print(hashtags)
我使用以下JSON文件作为结束完整JSON文件将使用的格式示例(通过twitter API检索的数据):
但是,我得到以下错误:
File "C:\Anaconda3\lib\json\decoder.py", line 357, in raw_decode
raise JSONDecodeError("Expecting value", s, err.value) from None
JSONDecodeError: Expecting value
虽然这似乎是一个相当简单的错误,但我似乎找不到补救的方法
任何帮助都将是一个感谢,我在编码相当生疏哈哈
目前没有回答
相关问题 更多 >
编程相关推荐