我假裝做的節日變量console.log出現在列表中,而不是一個數組。我如何將這些信息作爲一個簡單的對象來獲取?如何訪問一個json對象0使用JavaScript
我的JSON:
[{
"2016-10-10":[{"name":"Columbus Day","country":"US","date":"2016-10-10"}],
"2016-10-31":[{"name":"Halloween","country":"US","date":"2016-10-31"}]
}]
我的應用程序:
app.factory('calendario', function($http) {
return{
getJobs : function() {
return $http({
url: '/app/components/home/controller/test_calendar.json',
method: 'GET'
})
}
}
});
控制器:
var holidays = [];
calendario.getJobs().success(function(data){
holidays.push(data[0]);
});
$scope.setDayContent = function(date) {
console.log(holidays);
};
例子:
我想這
我不希望這
什麼是預期的輸出? – brk
[有沒有這樣的事情作爲「JSON對象」](http://benalman.com/news/2010/03/theres-no-such-thing-as-a-json/) – Andreas
刪除'[和']'從頭到尾。 –