gpt4 book ai didi

jQuery Ajax 访问 json

转载 作者:行者123 更新时间:2023-12-01 04:29:26 24 4
gpt4 key购买 nike

我一直在尝试访问 json 响应的某些部分,但我无法这样做。

json = '{

"now": "2010-09-23 22:06:53 EST",

"data":[

{"id":"1","year":"2010","month":"09","day":"23","hours":"08","minutes":"09","seconds":"25"},{"id":"8","year":"2010","month":"09","day":"23","hours":"08","minutes":"09","seconds":"18"}, {"id":"3","year":"2010","month":"09","day":"23","hours":"08","minutes":"09","seconds":"24"},{"id":"4","year":"2010","month":"09","day":"23","hours":"08","minutes":"09","seconds":"30"}]}';

我正在使用以下方法解析我的数据:

var resp = jQuery.parseJSON(json);
alert(resp.data);

例如,我如何访问 id 3 的月份?

谢谢

我尝试过alert(resp.data[0]),但没有成功。

最佳答案

尝试

$.each(resp.data,function(i,v){
if(v.id == 3) {
alert(v.month) // alerts "09"
}
});

关于jQuery Ajax 访问 json,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3784154/

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