gpt4 book ai didi

javascript - 通过 Javascript 访问 JSON 数组

转载 作者:行者123 更新时间:2023-11-30 12:28:44 27 4
gpt4 key购买 nike

我有一些像这样的 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]);

但我总是得到“undefined”,我真的不知道如何访问它

最佳答案

您的数据是一个数组 ([ ... ]),其中包含一个对象。

尝试:

console.log(hours[0][date]);

关于javascript - 通过 Javascript 访问 JSON 数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28419705/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com