[thelist] json_decode
Symeon Charalabides
symeon at systasis.com
Fri Jun 21 15:39:26 CDT 2013
Hi Bob,
Setting the 2nd parameter of json_decode to TRUE means it'll return an associative array, not an object. Just do:
$result = $obj['timezone'];
> -------Original Message-------
> From: Bob Meetin <bobm at dottedi.biz>
> To: thelist at lists.evolt.org <thelist at lists.evolt.org>
> Subject: [thelist] json_decode
> Sent: 21 Jun '13 19:08
>
> This seems simple enough, but it's not working. I have a json string to decode:
>
> <?php
> $json = {"admin_style":"","admin_language":"","language":"","editor":"jce","helpsite":"","timezone":"America\/Juneau"}; // this is pulled out of a mysql table
> $obj = json_decode($json, true);
> $result = $obj['0']->timezone; // This should pull the timezone value, yes?
>
> echo "Result: $result<br />";
> >
>
> Of course no result, so I tried quoting the sting with single ticks.
>
> <?php
> $json = {"admin_style":"","admin_language":"","language":"","editor":"jce","helpsite":"","timezone":"America\/Juneau"};
> $json = "'$json'";
> $obj = json_decode($json, true);
> $result = $obj['0']->timezone;
>
> echo "Result: $result<br />";
> >
>
> Also tried: $result = $obj[0]->timezone; // without ticks
>
> Still no result. What am I missing?
> Bob
Symeon Charalabides (cosmopolite trainee)
-----------------------------------------
http://www.systasis.com
http://twitter.com/bluesymeon
http://www.linkedin.com/in/symeon
More information about the thelist
mailing list