[thelist] json_decode
Dan Parry
dan at shaded.plus.com
Fri Jun 21 14:17:44 CDT 2013
Hi Bob
Correct me if I'm wrong but you're pulling the data from a database, right? This means the data you're getting is most likely a string. What you need to use is $obj = json_encode($json);
That will convert the string into the object you're expecting. If you still can't get $result try a var_dump() of $obj
I hope I haven't misunderstood or missed anything
Dan
-----Original Message-----
From: thelist-bounces at lists.evolt.org [mailto:thelist-bounces at lists.evolt.org] On Behalf Of Bob Meetin
Sent: 21 June 2013 20:09
To: thelist at lists.evolt.org
Subject: [thelist] json_decode
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
--
* * Please support the community that supports you. * *
http://evolt.org/help_support_evolt/
For unsubscribe and other options, including the Tip Harvester
and archives of thelist go to: http://lists.evolt.org
Workers of the Web, evolt !
More information about the thelist
mailing list