Page 1 of 1

json_decode array

Posted: Sun Mar 13, 2011 6:34 pm
by pedroz

Code: Select all

$url = 'http://www.domain.com';
$fb = json_decode($output);	
$count = $fb->{$url}{'shares'};

echo $count; // should be 942

to get the 942 result, what am i doing wrong?

Code: Select all

var_dump($output);
object(stdClass)#210 (1) { 
    ["http://www.domain.com"]=> object(stdClass)#211 (2) { 
         ["id"]=> string(19) "http://www.domain.com" 
         ["shares"]=> int(942) 
    } 
}

Re: json_decode array

Posted: Sun Mar 13, 2011 6:44 pm
by Weirdan

Code: Select all

$count = $fb->{"http://www.domain.com"}->{"shares"};

Re: json_decode array

Posted: Sun Mar 13, 2011 7:29 pm
by pedroz
Thanks.
It works when I use
$count = $fb->{"http://www.domain.com"}->shares;

but not with
$count = $fb->{$url}->shares;

Re: json_decode array

Posted: Sun Mar 13, 2011 7:31 pm
by pedroz
Sorry. I had 2 $url strings in the function messing it.

Thanks. It works!!!!