解析JSON时会添加额外数据

时间:2012-10-09 09:19:56

标签: ajax json parsing

我遇到了一个非常奇怪的问题。我有一些信息从PHP页面传回,我使用json_encode作为JSON数据发回。一旦我在调用页面上收到它,响应就是正确的(从firebug中查看响应)。

如果我在$ .ajax函数中接收到数据后调度数据,则会有一个添加的变量(y0)在响应中没有。 dataType设置为JSON,我的PHP页面确实设置了JSON头类型。问题似乎是ajax解析数据。

下面是我的ajax以及响应和记录的数据:

// AJAX方法

$.ajax({
        url : 'includes/build_graphs.php',
        data : 'file='+href,
        type : 'post',
        dataType : 'json',
        beforeSend : function(){},
        success : function(data){
            console.log(data);

            var series_data = [];
            for(var i=0; i<data.length; i++){
                series_data.push({
                    name: data[i].name+'[VPD]',
                    data: data[i].vpd,
                    color: palette.color()

                });
            }//for
            console.log(series_data);
            create_graph(series_data);
        }
    });

//来自PHP的Firebug响应

[{"name":"Project 1","vpd":[{"x":1348696800,"y":0},{"x":1348783200,"y":0},{"x":1348869600,"y":16},{"x":1348956000,"y":1},{"x":1349042400,"y":1},{"x":1349128800,"y":20},{"x":1349215200,"y":1},{"x":1349301600,"y":17},{"x":1349388000,"y":10},{"x":1349474400,"y":23},{"x":1349560800,"y":0},{"x":1349647200,"y":58}]},{"name":"Project 2","vpd":[{"x":1348696800,"y":7},{"x":1348783200,"y":0},{"x":1348869600,"y":7},{"x":1348956000,"y":0},{"x":1349042400,"y":0},{"x":1349128800,"y":12},{"x":1349215200,"y":2},{"x":1349301600,"y":17},{"x":1349388000,"y":11},{"x":1349474400,"y":10},{"x":1349560800,"y":0},{"x":1349647200,"y":20}]},{"name":"Project 3","vpd":[{"x":1348696800,"y":3},{"x":1348783200,"y":18},{"x":1348869600,"y":23},{"x":1348956000,"y":1},{"x":1349042400,"y":1},{"x":1349128800,"y":11},{"x":1349215200,"y":17},{"x":1349301600,"y":50},{"x":1349388000,"y":22},{"x":1349474400,"y":39},{"x":1349560800,"y":0},{"x":1349647200,"y":34}]},{"name":"Project 4","vpd":[{"x":1348696800,"y":0},{"x":1348783200,"y":66},{"x":1348869600,"y":13},{"x":1348956000,"y":0},{"x":1349042400,"y":0},{"x":1349128800,"y":3},{"x":1349215200,"y":3},{"x":1349301600,"y":9},{"x":1349388000,"y":71},{"x":1349474400,"y":48},{"x":1349560800,"y":0},{"x":1349647200,"y":80}]},{"name":"Project 5","vpd":[{"x":1348696800,"y":6},{"x":1348783200,"y":2},{"x":1348869600,"y":9},{"x":1348956000,"y":0},{"x":1349042400,"y":0},{"x":1349128800,"y":2},{"x":1349215200,"y":2},{"x":1349301600,"y":20},{"x":1349388000,"y":4},{"x":1349474400,"y":9},{"x":1349560800,"y":0},{"x":1349647200,"y":22}]},{"name":"Project 6","vpd":[{"x":1348696800,"y":0},{"x":1348783200,"y":0},{"x":1348869600,"y":0},{"x":1348956000,"y":0},{"x":1349042400,"y":0},{"x":1349128800,"y":0},{"x":1349215200,"y":0},{"x":1349301600,"y":0},{"x":1349388000,"y":0},{"x":1349474400,"y":0},{"x":1349560800,"y":0},{"x":1349647200,"y":21}]},{"name":"Project 7","vpd":[{"x":1348696800,"y":0},{"x":1348783200,"y":0},{"x":1348869600,"y":0},{"x":1348956000,"y":0},{"x":1349042400,"y":0},{"x":1349128800,"y":17},{"x":1349215200,"y":2},{"x":1349301600,"y":48},{"x":1349388000,"y":14},{"x":1349474400,"y":32},{"x":1349560800,"y":0},{"x":1349647200,"y":35}]},{"name":"Project 8","vpd":[{"x":1348696800,"y":13},{"x":1348783200,"y":0},{"x":1348869600,"y":23},{"x":1348956000,"y":0},{"x":1349042400,"y":1},{"x":1349128800,"y":15},{"x":1349215200,"y":2},{"x":1349301600,"y":27},{"x":1349388000,"y":14},{"x":1349474400,"y":32},{"x":1349560800,"y":0},{"x":1349647200,"y":72}]}]

//来自解析的JSON的一个条目(不幸的是,由于我无法发布图像,因此复制粘贴在firebug中) //我注意到这里有关于第9条的奇怪事情,但这可能是萤火虫,或者确实是问题

    name="Project 1",
vpd=[
    Object{
        x=1348696800,
        y=0,
        y0=0
    },
    Object{
        x=1348783200,
        y=0,
        y0=0
    },
    Object{
        x=1348869600,
        y=16,
        y0=0
    },
    9more...
]
 0 = Object{
    x=1348696800,
    y=0,
    y0=0
}
1 = Object{
    x=1348783200,
    y=0,
    y0=0
}
2 = Object{
    x=1348869600,
    y=16,
    y0=0
}
3 = Object{
    x=1348956000,
    y=1,
    y0=0
}
4 = Object{
    x=1349042400,
    y=1,
    y0=0
}
5 = Object{
    x=1349128800,
    y=20,
    y0=0
}
6 = Object{
    x=1349215200,
    y=1,
    y0=0
}
7 = Object{
    x=1349301600,
    y=17,
    y0=0
}
8 = Object{
    x=1349388000,
    y=10,
    y0=0
}
9 = "this.9"
10 = Object{
    x=1349560800,
    y=0,
    y0=0
}
11 = Object{
    x=1349647200,
    y=58,
    y0=0
}

提前致谢。

0 个答案:

没有答案