2017-04-02 9 views
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オブジェクトを渡す必要があります。

解決方法を教えてください。

ありがとうございます。代わりの

答えて

1

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

は行います

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

おかげで、質問は愚かなものです。今私は実現しました。実際に投稿した後、私はこのアイデアを得ました。私はちょうどjsonDataにserverjson objecをコピーする必要があります。それで全部です。 ありがとうございました。 – harshavmb

+0

はい、* serverjson *が実際にJSONか、既にJavaScriptオブジェクトかどうかによって異なります。最初のものであれば 'JSON.parse'が必要で、2番目の場合は変換が必要ありません。しかし、文字列でない場合は、変数 'jsonData'または' serverjson'を呼び出さないでください。JSONでないためです。 JSONはテキスト形式です。 JavaScriptオブジェクトはテキストではありません。 – trincot

関連する問題