JS 解析JSON实现导序
var chartData = [ { "online": '2013-10-23', "new": 0.00, "login": 0.00, "active": 0.00 }, { "online": '2013-10-22', "new": 0.00, "login": 0.00, "active": 0.00 }, { "online": '2013-10-21', "new": 0.00, "login": 0.00, "active": 0.00 }, { "online": '2013-10-19', "new": 0.00, "login": 0.00, "active": 0.00 }, { "online": '2013-10-18', "new": 1.50, "login": 1.50, "active": 1.50 }, { "online": '2013-10-17', "new": 0.00, "login": 0.00, "active": 0.00 }, { "online": '2013-10-16', "new": 0.00, "login": 0.00, "active": 0.00 } ]; var list = new Object; var j = 0; for (var i = (chartData.length-1); i >-1 ; i--) { list[j] = chartData[i]; j++; }; for(var i in list){ alert(JSON.stringify(list[i])); }
JSON.parson(); //alert(typeof(chartData));
parse用于从一个字符串中解析出json对象,如
var str = '{"name":"huangxiaojian","age":"23"}'
结果:
JSON.parse(str)
stringify()用于从一个对象解析出字符串,如
var a = {a:1,b:2}
结果:
JSON.stringify(a)
"{"a":1,"b":2}"