2012-03-24 78 views
3

我想让这个工作,但看不到我要去哪里错了。任何人都可以协助PHP json_decode带回null

<?php 
    $jsonurl  = 'http://www.foxsports.com.au/internal-syndication/json/livescoreboard'; 
    $json   = file_get_contents($jsonurl,0,null,null); 
    $json_output = var_dump(json_decode($json,true)); 

    echo $json_output 
?> 

回答

3

提示:

初始JSON(存储在$json变量)不验证。

代码:(固定)

<?php 

$jsonurl='http://www.foxsports.com.au/internal-syndication/json/livescoreboard'; 
$json = file_get_contents($jsonurl,0,null,null); 

$json = strip_tags(str_replace("jQuery.fs['scoreboard'].data =","",$json)); 

$json_output = var_dump(json_decode($json,true)); 

echo $json_output; 

?> 

这将工作。 :-)

+0

对不起,它不适合我我得到“NULL - 语法错误,格式错误的JSON”。它与引号中的json有什么关系? – Gopher 2012-03-24 21:21:20

+0

@Gopher它正在工作。与此同时,JSON突然包含...导致它崩溃的注释。给我一分钟,我会看看我们能做些什么...... – 2012-03-24 21:40:17

+0

@Gopher我们现在剥夺了评论('strip_tags'),它正在工作(再次);我已经检查过我自己现在... :-) – 2012-03-24 21:43:24