js将json转为二维数组
将json:
{'totalCount':6,'root':[{'dates':'0','amounts':'0'},{'dates':'2','amounts':'1'},{'dates':'4','amounts':'1.5'},{'dates':'6','amounts':'1.8'},{'dates':'8','amounts':'1.9'},{'dates':'10','amounts':'13'}]}
转为二维数组
js应该怎么写
------最佳解决方案--------------------http://blog.163.com/lucky215@126/blog/static/7843568820102280333808/
------其他解决方案--------------------eval方法或者jQuery的ParseJSON方法
------其他解决方案--------------------谢谢各位试下
------其他解决方案--------------------json.root[0],读的就是{'dates':'0','amounts':'0'}
------其他解决方案--------------------要在数据库中读取值并画折线图
后台得到的json数据为
{'totalCount':6,'root':[{'dates':'0','amounts':'0'},{'dates':'2','amounts':'1'},{'dates':'4','amounts':'1.5'},{'dates':'6','amounts':'1.8'},{'dates':'8','amounts':'1.9'},{'dates':'10','amounts':'13'}]}
前台为:
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Web._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
<LINK href="style/layout.css" rel="stylesheet" type="text/css">
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="../excanvas.min.js"></script><![endif]-->
<SCRIPT language="javascript" src="js/jquery.js" type="text/javascript"></SCRIPT>
<SCRIPT language="javascript" src="js/jquery.flot.js" type="text/javascript"></SCRIPT>
</head>
<body>
<form id="form1" runat="server">
<div>
<input type="hidden" id="result_values" value="<%=result %>" />
<DIV id="placeholder" style="width: 600px; height: 300px;"></DIV>
<script type="text/javascript">
$(function () {
var d1 = [];
for (var i = 0; i < 14; i += 0.5)
d1.push([i, Math.sin(i)]);
// var d4=(Array)(document.getElementById("result_values").value);
var d2 = [[4, 8],[0, 3], [8, 5], [9, 13]];
// var d3=[[0,0],[2,1],[4,1.5],[6,1.8],[8,1.9]];
//var str=document.getElementById("result_values").value;
// var d3= eval(str);
$.plot($("#placeholder"), [ d1, d2]);
});
</script>
</div>
</form>
</body>
</html>
有没有办法或其他画图方法
------其他解决方案--------------------谢谢各位解决了