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>
、締結する、私は$.getJSON()
機能にremote url
または.js
ファイルを渡していないよ、私はserverjson
オブジェクトを渡す必要があります。
解決方法を教えてください。
ありがとうございます。代わりの
おかげで、質問は愚かなものです。今私は実現しました。実際に投稿した後、私はこのアイデアを得ました。私はちょうどjsonDataにserverjson objecをコピーする必要があります。それで全部です。 ありがとうございました。 – harshavmb
はい、* serverjson *が実際にJSONか、既にJavaScriptオブジェクトかどうかによって異なります。最初のものであれば 'JSON.parse'が必要で、2番目の場合は変換が必要ありません。しかし、文字列でない場合は、変数 'jsonData'または' serverjson'を呼び出さないでください。JSONでないためです。 JSONはテキスト形式です。 JavaScriptオブジェクトはテキストではありません。 – trincot