带有json对象的$ .getJSON函数

时间:2017-04-02 12:40:35

标签: javascript jquery json

我有以下服务器端和客户端json处理代码的组合。我可以从@name和本地remote url文件加载json数据。 但是,不知怎的,我无法弄清楚如何从下面的代码片段中的.js对象加载数据。

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()个对象。

请帮我解决这个问题。

提前致谢。

1 个答案:

答案 0 :(得分:1)

而不是:

$.getJSON(---have to load data from json object----).done(function (jsonData) {
     // code
});

做的:

var jsonData = JSON.parse(serverjson);
// code