json数据未解析成

时间:2014-02-11 15:05:18

标签: javascript php json canvas

我尝试获取php数据,从MySQL检索,json编码到javascript文件中绘制线图。

我的json数据看起来像

  

php data.php

[
    {"x":"1","y":"925"},{"x":"2","y":"1000"},{"x":"3","y":"1000"},{"x":"4","y":"11"},{"x":"5","y":"52"},{"x":"6","y":"84"},{"x":"7","y":"109"},{"x":"8","y":"132"},{"x":"9","y":"270"},{"x":"10","y":"291"},{"x":"11","y":"306"},{"x":"12","y":"330"},{"x":"13","y":"356"},{"x":"14","y":"374"},{"x":"15","y":"395"},{"x":"16","y":"411"},
    ...
    {"x":"33","y":"887"},{"x":"34","y":"905"},{"x":"35","y":"921"},{"x":"36","y":"940"},{"x":"37","y":"1000"},{"x":"38","y":"1000"}
]

当尝试将此数据解析为我的js html并在浏览器中打开该页面时,它没有任何内容:

<script src="jquery.js"></script>
<script src="canvas/canvasjs.min.js"></script>

<script type="text/javascript">
    $(document).ready(function () {
        $.getJSON("data.php", function (result) {
            var chart = new CanvasJS.Chart("chartContainer",
                title:{
                    text: "Documents"
                }
                {
                    data: [{dataPoints: result}]
            });
            chart.render();
        });
    });
</script>
</head>

有人看到这里有什么问题吗?或者可以提供一些提示如何排除故障? 我正在研究chrome的开发人员工具,但这并没有显示任何错误。 感谢

2 个答案:

答案 0 :(得分:2)

你好像错过了一个逗号:

    text: "Documents"
}    // <-- There
{
    data: [{dataPoints: result}]

将其替换为:

    text: "Documents"
},   // <-- There
{
    data: [{dataPoints: result}]

答案 1 :(得分:0)

你在第一个对象的末尾错过了一个逗号