我有一些像这样的JSON数据:
[{"2015-02-10": ["00:00","00:30","01:00","01:30","02:00","02:30","03:00","03:30","04:00","04:30","05:00","05:30","06:00","06:30","07:00","07:30","12-00","12-30","13-00","13-30","18:00","18:30","19:00","19:30","20:00","20:30","21:00","21:30","22:00","22:30","23:00","23:30"]},{"2015-02-17": ["00:00","00:30","01:00","01:30","02:00","02:30","03:00","03:30","04:00","04:30","05:00","05:30","06:00","06:30","07:00","07:30","12-00","12-30","13-00","13-30","18:00","18:30","19:00","19:30","20:00","20:30","21:00","21:30","22:00","22:30","23:00","23:30"]}]
现在我在Javascript中解析它并尝试访问特定日期的值:
var hours = $.parseJSON('JSON STRING ...');
var date = "2015-02-10";
console.log(hours[date]);
但我总是得到“未定义”,我真的不知道如何访问这个
答案 0 :(得分:3)
您的数据是一个数组([ ... ]
),其中包含一个对象。
尝试:
console.log(hours[0][date]);