我在以下格式的url中包含日曆事件,它調用$ .getJSON。添加至getJSON的數據
[{"guid":"53c2d70ae6014","date":"1408161600000","type":"event","title":"Weekend Classes Begin","description":"","url":"" },
{"guid":"53c2d70ae601c","date":"1408248000000","type":"event","title":"Freshman Orientation","description":"","url":"" },
{"guid":"53c2d70ae6022","date":"1408334400000","type":"event","title":"Freshman Orientation","description":"","url":"" }]
它得到的JSON,並把它變成一個數組,當我使用alert(data);
它顯示爲
[object Object],[object Object],[object Object]...
我希望能夠到一個或多個事件添加到我收到data
從$.getJSON
來電。
$.getJSON(eventsOpts.eventsjson + "?limit="+limit+"&year="+year+"&month="+month+"&day="+day, function(data) {
if(localStorage.getItem('agenda') === null)
{
}
else
{
var json = localStorage.getItem('agenda');
var jsonObj = JSON.stringify(json);
data.push(json);
alert(data);
}
flags.eventsJson = data; // save data to future filters
getEventsData(flags.eventsJson, limit, year, month, day, direction);
}).error(function() {
showError("error no internet connection.");
});
我要追加的JSON是{"guid":"53c2e0a3d0680","date":"1418922000000","type":"event","title":"Fall 2014 Graduation","description":"","url":"" }
我得到的是
[object Object],[object Object],[object Object],{"guid":"53c2e0a3d0680","date":"1418922000000","type":"event","title":"Fall 2014 Graduation","description":"","url":"" }
不知道我在做什麼錯
顯示你如何追加,看起來像一個字符串,而不是一個對象。 –
請勿使用alert()來檢查變量。正如你所看到的,這並不是非常有用。改用瀏覽器控制檯(例如'console.log()')。 –