這裏是我的問題我怎麼會這個數組轉換爲這個JSON格式
當我運行下面的代碼是PHP和CodeIgniter的框架
$data= $datatable->result();
foreach ($data as $graph) {
$to_graph[] = "Date.UTC(".$graph->year.")," . $graph->ANN ;
}
return json_encode($to_graph);
我得到以下出來把
["Date.UTC(2040),934","Date.UTC(2040),1003","Date.UTC(2040),1747","Date.UTC(2040),1336","Date.UTC(2040),973","Date.UTC(2040),912","Date.UTC(2040),1112","Date.UTC(2040),793","Date.UTC(2040),973","Date.UTC(2040),786","Date.UTC(2040),759","Date.UTC(2040),1001","Date.UTC(2040),1221","Date.UTC(2040),1270","Date.UTC(2040),1355","Date.UTC(2040),923","Date.UTC(2040),942","Date.UTC(2040),999","Date.UTC(2040),1128","Date.UTC(2040),908"]
但是,如果要在圖表上繪製高圖,需要像這樣顯示它
[Date.UTC(2003),0.8709],
[Date.UTC(2003),0.872],
[Date.UTC(2003,26),0.8714],
[Date.UTC(2003),0.8638],
[Date.UTC(2003),0.8567],
[Date.UTC(2005),0.8536],
[Date.UTC(2005),0.8564],
[Date.UTC(2005),0.8639],
[Date.UTC(2009),0.8538],
[Date.UTC(2009),0.8489],
[Date.UTC(2009),0.8459],
[Date.UTC(20011),0.8521],
[Date.UTC(2011),0.6945]
]);
使你能幫助我在我的轉換JSON出向他提出的highstocks的不帶引號「」
感謝
所以這會改變數據可以通過highcharts上升?因爲如果你在上面的代碼中看到它,返回json_encode($ to_graph);做同樣的事情?我可能是錯的,但你可以詳細解釋一下...非常感謝 –
你想要的json輸出是無效的json。 –
我發佈的數據是從他們的頁面上的一個演示中獲得的。好的,如果它不是一個有效的JSON,那麼你能告訴我,我怎麼能使它有效?謝謝 –