Wednesday, 21 August 2013

Access item in JSON encoded string

Access item in JSON encoded string

First time working with JSON, been stuck for 2 hours on this. I'm trying
to access a specific item in a JSON encoded string using PHP, but running
into issues.
My code:
$json = json_encode($tweets);
$result = json_decode($json, true);
var_dump($result);
echo $result['text'];
Output
array(1) { [0]=> array(22) { ["created_at"]=> string(30) "Sat Jul 20
15:03:15 +0000 2013" ["id"]=> int(1234567) ["id_str"]=> string(18)
"1234567" ["text"]=> string(112) "we have a new billing address" } }
I want to access the ["text"] element only. Any ideas? Thanks!

No comments:

Post a Comment