解析ADS-B json文件

时间:2017-03-14 18:20:11

标签: python json parsing

我正在尝试解析ADS-B数据以提取我想要的特定元素的值。我在下面发布了一小部分json文件作为示例。我有python中的代码来读取文件,但我不知道如何提取特定的组件。例如,我对“Id”“Lat”和“Long”的所有值感兴趣。我该如何提取这些值?

Python代码:

import json

with open('Short_ADSB.json') as json_data:
    d = json.load(json_data)
    print(d)

Short_ADSB.json:

{"src":1,"feeds":[{"id":1,"name":"ADSBexchange.com","polarPlot":false}],"srcFeed":1,"showSil":true,"showFlg":true,"showPic":true,"flgH":20,"flgW":85,"acList":[{"Id":8721588,"Rcvr":1,"HasSig":false,"Icao":"8514B4","Bad":false,"Reg":"JA321J","FSeen":"\/Date(1466380828682)\/","TSecs":1,"CMsgs":1,"Alt":31000,"GAlt":31000,"AltT":0,"Tisb":false,"TrkH":false,"Type":"B738","Mdl":"Boeing 737NG 846/W","Man":"Boeing","CNum":"35350","Op":"Japan Airlines","OpIcao":"JAL","Sqk":"","VsiT":0,"WTC":2,"Species":1,"Engines":"2","EngType":3,"EngMount":0,"Mil":false,"Cou":"Japan","HasPic":false,"Interested":false,"FlightsCount":0,"Gnd":false,"SpdTyp":0,"CallSus":false,"TT":"a","Trt":1,"Year":"2009"},{"Id":2961715,"Rcvr":1,"HasSig":false,"Icao":"2D3133","Bad":false,"FSeen":"\/Date(1466380828682)\/","TSecs":1,"CMsgs":1,"InHg":29.9409447,"AltT":0,"Lat":0.0,"Long":-2147.483648,"PosTime":1466380828682,"Mlat":false,"Tisb":false,"Spd":11308.0,"TrkH":false,"Sqk":"","VsiT":0,"WTC":0,"Species":0,"EngType":0,"EngMount":0,"Mil":false,"Cou":"Unknown or unassigned country","HasPic":false,"Interested":false,"FlightsCount":0,"SpdTyp":0,"CallSus":false,"ResetTrail":true,"TT":"a","Trt":2,"Cos":[0.0,-2147.483648,1466380828682.0,null]}}

1 个答案:

答案 0 :(得分:0)

获取JSON上存在的属性的示例代码。希望您可以使用它作为样本来获取所需的属性。

import json

with open('Short_ADSB.json') as json_data:
    d = json.load(json_data)
    print(d)
    print(d["src"])
    print(d["feeds"])
    ## read from feeds array
    print(d["feeds"][0]["id"])
    print(d["acList"])
    print(d["acList"][0]["Id"])
print(d["acList"][1]["Lat"])
print(d["acList"][1]["Long"])