【发布时间】:2021-10-04 03:22:26
【问题描述】:
我正在使用 Twitter 的流 API 代码(找到 here)。我能够得到我想要的输出,这是一系列过滤结果。但是,我特别需要将 JSON 结果中的“文本”字段分配给一个变量,但我无法想出正确的方法。
我已经隔离了返回流数据的部分代码,并在我运行时显示在终端中:
for response_line in response.iter_lines():
if response_line:
json_response = json.loads(response_line)
print(json.dumps(json_response, indent=4, sort_keys=True))
我需要的是获取返回的推文的文本部分。这是一个输出示例,注意我只需要设置一个变量 - twitterVariable 到“文本”结果:
{
"data": {
"id": "125855555555",
"text": "hello this is a test"
},
"matching_rules": [
{
"id": 1234567890,
"tag": ""
}
]
}
【问题讨论】: