PHP json_decode brings back null

时光怂恿深爱的人放手 提交于 2019-12-14 01:06:48

问题


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

回答1:


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. :-)




回答2:


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



来源:https://stackoverflow.com/questions/9849562/php-json-decode-brings-back-null

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!