2012-03-24 81 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