2012-03-24 13 views
3

Ich versuche, dies zur Arbeit zu bringen, kann aber nicht sehen, wo ich falsch liege. Kann jemand helfen?PHP json_decode bringt 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 
?> 

Antwort

3

Hinweis:

Die anfängliche JSON (in $json Variable gespeichert) nicht validiert.

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; 

?> 

Dies funktioniert. :-)

+0

Sorry Es funktioniert nicht für mich bekomme ich "NULL - Syntaxfehler, fehlerhafte JSON". Hat es etwas damit zu tun, dass der JSON in Anführungszeichen steht? – Gopher

+0

@Gopher Es hat funktioniert. In der Zwischenzeit enthält der JSON plötzlich ... Kommentare, die ihn zum Absturz bringen. Gib mir eine Minute, und ich werde sehen, was wir tun können ... –

+0

@Gopher Wir entfernen jetzt Kommentare ('strip_tags'), und es funktioniert (wieder); Ich habe das gerade gerade überprüft ... :-) –