PHP json_decode brings back null

2019-06-25 14:35发布

I am trying to get this to work but can't see where I'm going wrong. Can anyone assist?

<?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条回答
The star\"
2楼-- · 2019-06-25 14:38

Your JSON source is not valid. You can try this validator http://jsonlint.com/

查看更多
Fickle 薄情
3楼-- · 2019-06-25 14:51

Hint :

The initial JSON (stored in $json variable) does NOT validate.

Code : (FIXED)

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

?>

This will work. :-)

查看更多
登录 后发表回答