未通过json对php数组进行编码

未通过json对php数组进行编码,php,javascript,json,Php,Javascript,Json,如果我打印($data) $drivetracker = simplexml_load_file('geot_5980.xml'); $data = array(); foreach ($drivetracker->plays->qtr as $qtr): foreach ($qtr->play as $myplay): $hasball = (string)$myplay['hasball']; $play = (string)$myplay[

如果我打印($data)

$drivetracker = simplexml_load_file('geot_5980.xml');
$data = array();
foreach ($drivetracker->plays->qtr as $qtr):
    foreach ($qtr->play as $myplay):
    $hasball = (string)$myplay['hasball'];
        $play = (string)$myplay['spot'];
        $down = (string)$myplay['down'];
    $togo = (string)$myplay['togo'];
    $type = (string)$myplay['type'];
    $text = (string)$myplay['text'];
        if($drive == $driveid){
                array_push($data, array("text" => $text,               
                "spot" => $play,
                "ball" => $hasball,
                "togo" => $togo,
                "type" => $type,
                "drive"=> $drive)
           );
            }
    }
    endforeach;
endforeach;

echo json_encode($data); 
但是如果我做了
echo json_encode($data)
它没有给我这种格式。。。(它给了我空白)

$data未通过json编码的可能原因是什么

这是来自print_r($data)


输出是什么?我是否只需输入echo json_last_error();echo json_encode($data);?因为这也会给我空白,所以您的打印输出毫无意义:
)=>Array
它对我有效:您是否尝试删除
(字符串)
Array
(
    [0] => Array
        (
            [text] => Godhigh, R. rush for 2 yards to the GT27 (Canty, W).
            [spot] => GT25
            [ball] => GT
            [togo] => 10
            [type] => R
            [drive] => 7
        )

    [1] => Array
        (
            [text] => Days, S. rush for 5 yards to the GT32 (Woodruff, J;Brown, Ky).
            [spot] => GT27
            [ball] => GT
            [togo] => 8
            [type] => R
            [drive] => 7
        )

    [2] => Array
        (
            [text] => Sims, D. rush for 6 yards to the GT38, 1ST DOWN GT (Anunike, K;Sarmiento, S).
            [spot] => GT32
            [ball] => GT
            [togo] => 3
            [type] => R
            [drive] => 7
        )

    [3] => Array
        (
            [text] => Godhigh, R. rush for 18 yards to the DU44, 1ST DOWN GT (Cockrell, R).
            [spot] => GT38
            [ball] => GT
            [togo] => 10
            [type] => R
            [drive] => 7
        )

    [4] => Array
        (
            [text] => Lee, V. pass complete to Greene, J. for 5 yards to the DU39 (Foster, T).
            [spot] => DU44
            [ball] => GT
            [togo] => 10
            [type] => P
            [drive] => 7
        )

    [5] => Array
        (
            [text] => Laskey, Z. rush for 9 yards to the DU35 (Sink, N).
            [spot] => DU44
            [ball] => GT
            [togo] => 10
            [type] => R
            [drive] => 7
        )

    [6] => Array
        (
            [text] => Laskey, Z. rush for 5 yards to the DU30, 1ST DOWN GT (Canty, W;France, C).
            [spot] => DU35
            [ball] => GT
            [togo] => 1
            [type] => R
            [drive] => 7
        )

    [7] => Array
        (
            [text] => Laskey, Z. rush for 4 yards to the DU26 (Sink, N).
            [spot] => DU30
            [ball] => GT
            [togo] => 10
            [type] => R
            [drive] => 7
        )

    [8] => Array
        (
            [text] => Lee, V. rush for 3 yards to the DU23 (Brown, Ky).
            [spot] => DU26
            [ball] => GT
            [togo] => 6
            [type] => R
            [drive] => 7
        )

    [9] => Array
        (
            [text] => Laskey, Z. rush for 5 yards to the DU18, 1ST DOWN GT (Canty, W).
            [spot] => DU23
            [ball] => GT
            [togo] => 3
            [type] => R
            [drive] => 7
        )

    [10] => Array
        (
            [text] => Smith, O. rush for 8 yards to the DU10 (France, C).
            [spot] => DU18
            [ball] => GT
            [togo] => 10
            [type] => R
            [drive] => 7
        )

    [11] => Array
        (
            [text] => Lee, V. rush for 4 yards to the DU6, 1ST DOWN GT (France, C).
            [spot] => DU10
            [ball] => GT
            [togo] => 2
            [type] => R
            [drive] => 7
        )

    [12] => Array
        (
            [text] => Laskey, Z. rush for 3 yards to the DU3 (Helton, D;Woodruff, J).
            [spot] => DU06
            [ball] => GT
            [togo] => 0
            [type] => R
            [drive] => 7
        )

    [13] => Array
        (
            [text] => Laskey, Z. rush for no gain to the DU3 (Woodruff, J;Brown, Ky).
            [spot] => DU03
            [ball] => GT
            [togo] => 0
            [type] => R
            [drive] => 7
        )

    [14] => Array
        (
            [text] => Smith, O. rush for 1 yard to the DU2 (France, C).
            [spot] => DU03
            [ball] => GT
            [togo] => 0
            [type] => R
            [drive] => 7
        )

    [15] => Array
        (
            [text] => Lee, V. rush for 2 yards to the DU0, TOUCHDOWN, clock 04:34.
            [spot] => DU02
            [ball] => GT
            [togo] => 0
            [type] => R
            [drive] => 7
        )

    [16] => Array
        (
            [text] => Tanner, C. kick attempt good.
            [spot] => DU03
            [ball] => GT
            [togo] => 0
            [type] => X
            [drive] => 7
        )

    [17] => Array
        (
            [text] => Tanner, C. kickoff 51 yards to the DU14, Butler, L return 16 yards to the DU30 (Noble, D.).
            [spot] => GT35
            [ball] => GT
            [togo] => 0
            [type] => K
            [drive] => 7
        )

) => Array
        (
            [text] => Tanner, C. kickoff 51 yards to the DU14, Butler, L return 16 yards to the DU30 (Noble, D.).
            [spot] => GT35
            [ball] => GT
            [togo] => 0
            [type] => K
            [drive] => 7
        )

) 
[{"text":"","spot":"","ball":"","togo":"0","type":"","drive":""},{"text":"","spot":"","ball":"","togo":"0","type":"","drive":""},{"text":"","spot":"","ball":"","togo":"0","type":"","drive":""},{"text":"","spot":"","ball":"","togo":"0","type":"","drive":""},{"text":"","spot":"","ball":"","togo":"0","type":"","drive":""}]
Array ( [0] => Array ( [text] => Godhigh, R. rush for 2 yards to the GT27 (Canty, W). [spot] => GT25 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [1] => Array ( [text] => Days, S. rush for 5 yards to the GT32 (Woodruff, J;Brown, Ky). [spot] => GT27 [ball] => GT [togo] => 8 [type] => R [drive] => 7 ) [2] => Array ( [text] => Sims, D. rush for 6 yards to the GT38, 1ST DOWN GT (Anunike, K;Sarmiento, S). [spot] => GT32 [ball] => GT [togo] => 3 [type] => R [drive] => 7 ) [3] => Array ( [text] => Godhigh, R. rush for 18 yards to the DU44, 1ST DOWN GT (Cockrell, R). [spot] => GT38 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [4] => Array ( [text] => Lee, V. pass complete to Greene, J. for 5 yards to the DU39 (Foster, T). [spot] => DU44 [ball] => GT [togo] => 10 [type] => P [drive] => 7 ) [5] => Array ( [text] => Laskey, Z. rush for 9 yards to the DU35 (Sink, N). [spot] => DU44 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [6] => Array ( [text] => Laskey, Z. rush for 5 yards to the DU30, 1ST DOWN GT (Canty, W;France, C). [spot] => DU35 [ball] => GT [togo] => 1 [type] => R [drive] => 7 ) [7] => Array ( [text] => Laskey, Z. rush for 4 yards to the DU26 (Sink, N). [spot] => DU30 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [8] => Array ( [text] => Lee, V. rush for 3 yards to the DU23 (Brown, Ky). [spot] => DU26 [ball] => GT [togo] => 6 [type] => R [drive] => 7 ) [9] => Array ( [text] => Laskey, Z. rush for 5 yards to the DU18, 1ST DOWN GT (Canty, W). [spot] => DU23 [ball] => GT [togo] => 3 [type] => R [drive] => 7 ) [10] => Array ( [text] => Smith, O. rush for 8 yards to the DU10 (France, C). [spot] => DU18 [ball] => GT [togo] => 10 [type] => R [drive] => 7 ) [11] => Array ( [text] => Lee, V. rush for 4 yards to the DU6, 1ST DOWN GT (France, C). [spot] => DU10 [ball] => GT [togo] => 2 [type] => R [drive] => 7 ) [12] => Array ( [text] => Laskey, Z. rush for 3 yards to the DU3 (Helton, D;Woodruff, J). [spot] => DU06 [ball] => GT [togo] => 0 [type] => R [drive] => 7 ) [13] => Array ( [text] => Laskey, Z. rush for no gain to the DU3 (Woodruff, J;Brown, Ky). [spot] => DU03 [ball] => GT [togo] => 0 [type] => R [drive] => 7 ) [14] => Array ( [text] => Smith, O. rush for 1 yard to the DU2 (France, C). [spot] => DU03 [ball] => GT [togo] => 0 [type] => R [drive] => 7 ) [15] => Array ( [text] => Lee, V. rush for 2 yards to the DU0, TOUCHDOWN, clock 04:34. [spot] => DU02 [ball] => GT [togo] => 0 [type] => R [drive] => 7 ) [16] => Array ( [text] => Tanner, C. kick attempt good. [spot] => DU03 [ball] => GT [togo] => 0 [type] => X [drive] => 7 ) [17] => Array ( [text] => Tanner, C. kickoff 51 yards to the DU14, Butler, L return 16 yards to the DU30 (Noble, D.). [spot] => GT35 [ball] => GT [togo] => 0 [type] => K [drive] => 7 ) )