Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/277.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
带python问题的嵌套JSON_Python_Json_Nested - Fatal编程技术网

带python问题的嵌套JSON

带python问题的嵌套JSON,python,json,nested,Python,Json,Nested,所以我甚至不确定我问的问题是否正确。 我需要拉的是lat、long和航班号。 我可以打印/拖动一个叫做“地理”的字段/集合的整个部分,以及整个飞机的部分,但只要拉一拉,我就会撞到墙上。 JSON片段 [ { "geography": { "latitude": "27.3200", "longitude": "50.5700", "altitude": 12496.8, "di

所以我甚至不确定我问的问题是否正确。 我需要拉的是lat、long和航班号。 我可以打印/拖动一个叫做“地理”的字段/集合的整个部分,以及整个飞机的部分,但只要拉一拉,我就会撞到墙上。 JSON片段

[
    {
        "geography": {
            "latitude": "27.3200",
            "longitude": "50.5700",
            "altitude": 12496.8,
            "direction": "144.00"
        },
        "speed": {
            "horizontal": 1003.784,
            "isGround": 0,
            "vertical": 0
        },
.... (several other chunks like this, one per aircraft...)
}]
我正在尝试使用的代码

def json_filter(airline):
    with open('geo/'+ airline +'.json') as f:
      data = json.load(f)
      x = len(data)
      print(x)
      for d in range(0,x):
            #print (data[d]["aircraft"])
            print (data[d]["iataNumber"])
            print (data[d]["latitude"])
            print (data[d]["longitude"])
我走对了吗?或者有人能帮我解决问题或解释一下问题吗?

你可以这样做。。。
数据[d]
仅访问单个对象,地理位置是属性,因此,您还必须通过订阅来访问它

def json_filter(airline):
with open('geo/'+ airline +'.json') as f:
  data = json.load(f)
  x = len(data)
  print(x)
  for d in range(0,x):
        print (data[d]["geography"]["latitude"])
        print (data[d]["speed"]["horizontal"])
你可以这样做。。。
数据[d]
仅访问单个对象,地理位置是属性,因此,您还必须通过订阅来访问它

def json_filter(airline):
with open('geo/'+ airline +'.json') as f:
  data = json.load(f)
  x = len(data)
  print(x)
  for d in range(0,x):
        print (data[d]["geography"]["latitude"])
        print (data[d]["speed"]["horizontal"])

此外,您可以直接迭代
数据的元素
,而无需借助索引<数据中d的code>值:d[“地理”][“纬度”]等。此外,您可以直接迭代
数据的元素,而无需借助索引<数据中d的代码>为:d[“地理”][“纬度”]
等。