PHP的json_decode返回null

4

我试图让这个工作起来,但是不知道出了哪里问题。有人能帮忙吗?

<?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
?>
2个回答

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;

?>

这会起作用。:-)

抱歉,它对我不起作用,我收到了“NULL-语法错误,JSON格式不正确”的消息。这是否与JSON被引号括起来有关? - Gopher
@Gopher 它之前是可以工作的。但与此同时,JSON 突然包含了注释,导致它崩溃了。给我一分钟,我会看看我们能做些什么... - Dr.Kameleon
@Gopher,我们现在正在剥离注释(strip_tags),而且它又可以工作了;我刚刚亲自检查过了... :-) - Dr.Kameleon
谢谢Kameleon博士的快速回复。现在它对我有效了。 - Gopher

1

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接