【问题标题】:PHP json_decode brings back nullPHP json_decode 带回 null
【发布时间】:2023-03-31 12:01:02
【问题描述】:

我正在尝试让它工作,但看不到哪里出错了。有人可以帮忙吗?

<?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
?>

【问题讨论】:

    标签: php json file-get-contents


    【解决方案1】:

    提示:

    初始 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 它工作正常。与此同时,JSON 突然包含...导致它崩溃的 cmets。给我一分钟,我会看看我们能做些什么......
    • @Gopher 我们现在正在剥离 cmets (strip_tags),它正在工作(再次);我现在已经检查过自己... :-)
    • 感谢 Dr.Kameleon 的快速响应。它现在对我有用。
    【解决方案2】:

    您的 JSON 源代码无效。你可以试试这个验证器http://jsonlint.com/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-09-13
      • 2018-05-27
      • 1970-01-01
      • 2019-04-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多