tags:

views:

173

answers:

3

I'm decoding some JSON (from the Youtube data API) with json_decode and it gives me an object that looks like this when var_dump()ed:

object(stdClass)[29]
  public 'type' => string 'text' (length=4)
  public '$t' => string 'Miley and Mandy! KCA VIDEO WINNERS' (length=34)

How can I access the $t member?

+3  A: 

Try

$member = '$t';
$obj->$member
Andrei Serdeliuc
Fantastic! Thank you so much :)
xanadu
+1  A: 

You may use the second argument of json_decode

$data = json_decode($text, true);
echo $data['$t'];
VirtualBlackFox
That's also a nice solution, thanks!
xanadu
A: 

$t will only interpreted as a variable reference when used outside of quotes, or within double quotes ("$t"). Strings enclosed in single quotes ('$t') are not parsed for variable references.

echo $data['$t'];

Will do exactly what you want.

KOGI