read through json number array using javascript loop
This question already has an answer here:
You will become an array of objects, that includes an callEvent object that has an dates property which is an array with objects with the propertys startDateTime and endDateTime. It will look like following:
[
{
callEvent: {
dates: [
{startDateTime: '', endDateTime: ''},
// more objects with start- and endDateTime
]
}
},
// more callEvent objects..
]
Now your code should loop throug the array to get all callEvent objects and loop through all dates objects inside each callEvent.
$(document).ready(function () {
$.getJSON('http://app.toronto.ca/cc_sr_v1_app/data/edc_eventcal_APR?limit=500', function (array) {
// loop through all elements in the array
for (var i = 0; i < array.length; i++) {
// loop through all dates inside the array
for (var j = 0; j < array[i].calEvent.dates.length; j++) {
console.log(array[i].callEvent.dates[j].startDateTime)
console.log(array[i].callEvent.dates[j].endDateTime)
}
}
});
});
假设日期是有效的JSON(JSON Validator),那么你应该能够获取数据并循环遍历它:
for (var i=0;i<data.length;++i) {
console.log(data[i].startDateTime);
console.log(data[i].endDateTime);
}
链接地址: http://www.djcxy.com/p/24538.html
上一篇: 如何循环和保存JSON数组中的值