I am so close given everything I have read. Really I have been working on this and trying to understand this for a couple days. Endless google searches, and php manual reading of examples. I just don't think I have hit that AHA! moment where it clicks with me.
JSON Source
object(stdClass)#1 (2) {
["type"]=>
string(7) "success"
["response"]=>
object(stdClass)#2 (2) {
["data"]=>
object(stdClass)#3 (1) {
["songs"]=>
array(10) {
[0]=>
object(stdClass)#4 (2) {
["title"]=>
string(36) "Red Hot Chilly Peppers - Scar Tissue"
["time"]=>
int(1426114367)
}
[1]=>
object(stdClass)#5 (2) {
["title"]=>
string(29) "Rock Solid Radio Station ID 2"
["time"]=>
int(1426114359)
}
[2]=>
object(stdClass)#6 (2) {
["title"]=>
string(32) "Nirvana - Come As You Are (1991)"
["time"]=>
int(1426114150)
}
}
["message"]=>
string(8) "Complete"
}
}
JSON All Pretty (from validator)
{
"type": "success",
"response": {
"data": {
"songs": [
{
"title": "I Bet My Life - Imagine Dragons - I Bet My Life - Imagine Dragons",
"time": 1426176140
},
{
"title": "Smashing Pumpkins - Mayonaise",
"time": 1426175786
}
]
},
"message": "Complete"
}
}
Trying to get just the Title of the first song in the list, instead of all of them that come out.
Here is what my code looks like
<?php
error_reporting(E_ALL);
$str = "http://url/to/JSON";
$json = json_decode($str);
echo $json['type']['response']['data']['songs'][0]->title;
?>
I get this error. Notice: Trying to get property of non-object in /home/WackyShmacky/public_html/ouch/test/example2.php on line 6
Line 6:
echo $json['type']['response']['data']['songs'][0]->title;
This is clearly a problem with correct syntax and formatting, and I have looked at tons of examples, and it still has not clicked with me. Help would be greatly appreciated so I can put this behind me.