0
我有以下服務器端和客戶端JSON處理代碼的組合。我可以從remote url
和本地.js
文件加載json數據。 但是,不知何故,我無法弄清楚如何從下面的代碼片段中的serverjson
對象加載數據。
var json ;
<#list jsons as json>
serverjson = ${json};
console.log(serverjson);
$.getJSON(---have to load data from json object----).done(function (jsonData) {
var time = 0; var curc = 0; var prec = 0;
$.each(jsonData.current.timeSeries, function(i,item){
//console.log(jsonData.current.timeSeries[i].beginTimeSeconds+" : "+jsonData.current.timeSeries[i].endTimeSeconds+" : "+jsonData.current.timeSeries[i].inspectedCount);
time = jsonData.current.timeSeries[i].beginTimeSeconds;
curc = jsonData.current.timeSeries[i].inspectedCount;
//curdata.addRows([curc]);
curdata.push(curc)
//data.addRows([[jsonData.current.timeSeries[i].beginTimeSeconds,jsonData.current.timeSeries[i].endTimeSeconds,jsonData.current.timeSeries[i].inspectedCount]]);
});
</#list>
所以,最後,我不是過客remote url
或.js
文件中的$.getJSON()
功能,我需要通過serverjson
對象。
請幫我解決這個問題。
在此先感謝。
謝謝,這個問題是一個愚蠢的一個。現在我意識到了。事實上,發佈後我有這個想法。我只需要將serverjson對象複製到jsonData。就這樣。 非常感謝。 – harshavmb
是的,它取決於* serverjson *是否真的是JSON,或者已經是一個JavaScript對象。如果是第一個,則需要'JSON.parse',如果是第二個,則不需要轉換。但有人建議:如果變量不是字符串,請不要調用變量'jsonData'或'serverjson',因爲那時它們不是JSON。 JSON是一種文本格式。 JavaScript對象不是文本。 – trincot