Récupération données JSON
Bonsoir,
J'ai un petit problème avec un script pour récupérer des données dans un fichier JSON. Je n'arrive pas à récupérer la valeur $title qui se trouve à la ligne 131 du contenu JSON. Donc le script contient une erreur à la ligne 9, le problème vient de ce bout: [source], j'ai tout essayé mais sans succès et mon meilleur ami (Google) n'arrive pas à m'aider...:(
Je bloque sur ce bout de code depuis cet après-midi (non non je mens pas:D) J'espère que quelqu'un pourra m'aiguiller sur ce problème car j'ai bientôt plus de cheveux.
Merci d'avance et meilleures salutations.
Le script
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
| <?php
$json = file_get_contents("http://audio.true.nl/status-json.xsl");
//var_dump(json_decode($json));
$parsed_json = json_decode($json);
$admin = $parsed_json->{'icestats'}->{'admin'};
$host = $parsed_json->{'icestats'}->{'host'};
$title = $parsed_json->{'icestats'}[source]->{'9'}->{'title'};
echo "${host}<br />";
echo "${title}";
?> |
Le contenu JSON
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
| object(stdClass)#12 (1) {
["icestats"]=>
object(stdClass)#1 (4) {
["admin"]=>
string(15) "support@true.nl"
["host"]=>
string(13) "audio.true.nl"
["location"]=>
string(2) "NL"
["source"]=>
array(10) {
[0]=>
object(stdClass)#2 (3) {
["listeners"]=>
int(0)
["listenurl"]=>
string(33) "http://audio.true.nl:80/BESTOFDQ1"
["dummy"]=>
NULL
}
[1]=>
object(stdClass)#3 (3) {
["listeners"]=>
int(0)
["listenurl"]=>
string(29) "http://audio.true.nl:80/BLACK"
["dummy"]=>
NULL
}
[2]=>
object(stdClass)#4 (3) {
["listeners"]=>
int(0)
["listenurl"]=>
string(28) "http://audio.true.nl:80/BLUE"
["dummy"]=>
NULL
}
[3]=>
object(stdClass)#5 (3) {
["listeners"]=>
int(0)
["listenurl"]=>
string(27) "http://audio.true.nl:80/RED"
["dummy"]=>
NULL
}
[4]=>
object(stdClass)#6 (3) {
["listeners"]=>
int(0)
["listenurl"]=>
string(26) "http://audio.true.nl:80/UV"
["dummy"]=>
NULL
}
[5]=>
object(stdClass)#7 (12) {
["audio_codecid"]=>
int(2)
["bitrate"]=>
int(192)
["genre"]=>
string(26) "hardcore hardstyle olskool"
["listeners"]=>
int(11)
["listenurl"]=>
string(27) "http://audio.true.nl:80/b2s"
["metadata_updated"]=>
string(26) "04/Jul/2016:23:57:39 +0200"
["server_description"]=>
string(11) "Phatt beats"
["server_name"]=>
string(26) "b2s Radio Phatt Beats Only"
["server_type"]=>
string(10) "audio/mpeg"
["server_url"]=>
string(17) "http://www.b2s.nl"
["title"]=>
string(43) "Don Diablo - Starlight (Adrenalize Bootleg)"
["yp_currently_playing"]=>
string(43) "Don Diablo - Starlight (Adrenalize Bootleg)"
}
[6]=>
object(stdClass)#8 (3) {
["listeners"]=>
int(0)
["listenurl"]=>
string(43) "http://audio.true.nl:80/dehovenpassageradio"
["dummy"]=>
NULL
}
[7]=>
object(stdClass)#9 (3) {
["listeners"]=>
int(0)
["listenurl"]=>
string(36) "http://audio.true.nl:80/mediamarktfm"
["dummy"]=>
NULL
}
[8]=>
object(stdClass)#10 (3) {
["listeners"]=>
int(0)
["listenurl"]=>
string(30) "http://audio.true.nl:80/nuflow"
["dummy"]=>
NULL
}
[9]=>
object(stdClass)#11 (11) {
["audio_codecid"]=>
int(2)
["bitrate"]=>
int(128)
["genre"]=>
string(7) "various"
["listeners"]=>
int(247)
["listenurl"]=>
string(35) "http://audio.true.nl:80/qdance-hard"
["metadata_updated"]=>
string(26) "04/Jul/2016:23:57:19 +0200"
["server_description"]=>
string(45) "Representing the harder styles in dance music"
["server_name"]=>
string(13) "Q-dance Radio"
["server_type"]=>
string(10) "audio/mpeg"
["title"]=>
string(35) "Distorted Souls - Temple Of Anarchy"
["yp_currently_playing"]=>
string(35) "Distorted Souls - Temple Of Anarchy"
}
}
}
} |