0
不知道我在做什麼錯,我試圖從中獲取json數據並運行代碼。如果我直接輸入數據,一切正常。在jQuery中解析json錯誤
解析JSON(不工作):
function showprice(pricedata){
var obj = jQuery.parseJSON(pricedata);
console.log(obj.created);
console.log(obj.price);
label = obj.created;
values = obj.price;
var data = {
labels : [obj.created], //obj.created = "2013-12-30 14:20:29","2013-12-30 15:14:48","2013-12-30 14:32:29","2013-12-30 14:26:29"
values : [obj.price], //obj.price = 28.41,28.41,72.42,60.42
datasets : [
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [obj.price],...
數據直接輸入到代碼(工程):
function showprice(pricedata){
var obj = jQuery.parseJSON(pricedata);
console.log(obj.created);
console.log(obj.price);
label = obj.created;
values = obj.price;
var data = {
labels : ["2013-12-30 14:20:29","2013-12-30 15:14:48","2013-12-30 14:32:29","2013-12-30 14:26:29"], //obj.created = "2013-12-30 14:20:29","2013-12-30 15:14:48","2013-12-30 14:32:29","2013-12-30 14:26:29"
values : [28.41,28.41,72.42,60.42], //obj.price = 28.41,28.41,72.42,60.42
datasets : [
{
fillColor : "rgba(151,187,205,0.5)",
strokeColor : "rgba(151,187,205,1)",
pointColor : "rgba(151,187,205,1)",
pointStrokeColor : "#fff",
data : [28.41,28.41,72.42,60.42],
mouseover: function(data) {...
什麼是'pricedata'? –
您是否嘗試刪除obj.created和obj.price附近的「[]」? – cretzzzu3000
刪除「[]」不起作用。 – treska