javascript - How to decode the JSON array into two varibale? -
in given function i'm passing data in json format
[{"date":"2014-12-12 18:52:10","ttc":"0"},{"date":"2014-12-12 18:52:10","ttc":"0"},{"date":"2014-12-12 18:53:10","ttc":"0"},{"date":"2014-12-12 18:53:10","ttc":"0"},{"date":"2014-12-12 19:02:11","ttc":"0"}]
the json array long , want store date date array , ttc ttc please parse this.
function drawchart(data){ console.log(data); var date = []; var ttc = []; for(var i=0; i<data.length; i++){ date.push(data[i]['date']); console.log(date); ttc.push(parseint(data[i]["ttc"])); //console.log(ttc); } }
try way:
var data = [{ "date": "2014-12-12 18:52:10", "ttc": "0" }, { "date": "2014-12-12 18:52:10", "ttc": "0" }, { "date": "2014-12-12 18:53:10", "ttc": "0" }, { "date": "2014-12-12 18:53:10", "ttc": "0" }, { "date": "2014-12-12 19:02:11", "ttc": "0" }]; function drawchart(data) { var date = []; var ttc = []; (var = 0; < data.length; i++) { date.push(data[i]['date']); ttc.push(parseint(data[i]["ttc"])); } return { date: date, ttc: ttc }; } document.body.innerhtml = json.stringify(drawchart(data));
you need return object contain arrays
Comments
Post a Comment