【发布时间】:2019-05-27 23:39:37
【问题描述】:
我一直在使用下面的 Python 脚本尝试从 Flightradar24 中检索和提取一些数据,它似乎以 JSON 格式提取数据,并使用json.dumps 完全打印数据,但是当我尝试使用get 选择我想要的数据(在这种情况下为状态文本)会出现以下错误:
'list' 对象没有属性 'get'
数据是 JSON 还是列表?我现在完全糊涂了。
我对处理 JSON 格式的数据还很陌生,如果有任何帮助,我将不胜感激!
脚本:
import flightradar24
import json
flight_id = 'BA458'
fr = flightradar24.Api()
flight = fr.get_flight(flight_id)
y = flight.get("data")
print (json.dumps(flight, indent=4))
X= (flight.get('result').get('response').get('data').get('status').get('text'))
print (X)
输出数据样本:
{
"result": {
"request": {
"callback": null,
"device": null,
"fetchBy": "flight",
"filterBy": null,
"format": "json",
"limit": 25,
"page": 1,
"pk": null,
"query": "BA458",
"timestamp": null,
"token": null
},
"response": {
"item": {
"current": 16,
"total": null,
"limit": 25
},
"page": {
"current": 1,
"total": null
},
"timestamp": 1546241512,
"data": [
{
"identification": {
"id": null,
"row": 4852575431,
"number": {
"default": "BA458",
"alternative": null
},
"callsign": null,
"codeshare": null
},
"status": {
"live": false,
"text": "Scheduled",
"icon": null,
"estimated": null,
"ambiguous": false,
"generic": {
"status": {
"text": "scheduled",
"type": "departure",
"color": "gray",
"diverted": null
},
【问题讨论】:
标签: python json list dictionary nested