I've read through many similar posts but I can't seem to get it to work right. I can parse and the whole json file, it's a chart from Shazam. I'm stuck on selecting nested keys and get their values. How can I get only the artist, title and numberOfShazams values into attributes?
Here is my code so far:
<?php
$json = file_get_contents('http://cdn.shazam.com/shazam/v2/en/MX/android/-/tracks/web_chart_world');
$json_data = json_decode($json,true);
$jsonIterator = new RecursiveIteratorIterator(
new RecursiveArrayIterator(json_decode($json, TRUE)),
RecursiveIteratorIterator::SELF_FIRST);
foreach ($jsonIterator as $key => $val) {
if(is_array($val)) {
echo "$key:<br>";
} else {
echo "$key => $val<br>";
}
}
?>