如何访问此多级json文件中的特定数据?

时间:2018-03-25 03:07:11

标签: javascript php jquery arrays json

我有一个JSON文件:

{  
   "request":{  
      "command":"series",
      "series_id":"PET.EMD_EPD2DXL0_PTE_NUS_DPG.W"
   },
   "series":[  
      {  
         "series_id":"PET.EMD_EPD2DXL0_PTE_NUS_DPG.W",
         "name":"U.S. No 2 Diesel Ultra Low Sulfur (0-15 ppm) Retail Prices, Weekly",
         "units":"Dollars per Gallon",
         "f":"W",
         "unitsshort":"$\/gal",
         "description":"U.S. No 2 Diesel Ultra Low Sulfur (0-15 ppm) Retail Prices",
         "copyright":"None",
         "source":"EIA, U.S. Energy Information Administration",
         "iso3166":"USA",
         "geography":"USA",
         "start":"20070205",
         "end":"20180319",
         "updated":"2018-03-19T17:20:45-0400",
         "data":[  
            [  
               "20180319",
               2.972
            ],
            [  
               "20070205",
               2.463
            ]
         ]
      }
   ]
}

如何使用javascript或甚至php访问"数据" 中的值 2.972

使用javascript我试图在控制台中输出它:

var globalJSON;
jQuery.getJSON('myfile.json', function(data) {

    globalJSON = data;
    dataReady();

});

function dataReady(){

console.log(globalJSON.series.data[0]);

}

我收到错误"无法读取属性'数据'未定义的,无论我做什么,它都不会在" globalJSON.series"之后打印任何内容。非常感谢任何帮助,谢谢!

0 个答案:

没有答案