访问JSON编码字符串中的项目

时间:2013-08-22 00:20:14

标签: php json

第一次使用JSON时,已经停留了2个小时。我正在尝试使用PHP访问JSON编码字符串中的特定项目,但遇到了问题。

我的代码:

$json = json_encode($tweets);

$result = json_decode($json, true);

var_dump($result);

echo $result['text'];

输出

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" 
  }

}

我只想访问[“text”]元素。有任何想法吗?谢谢!

1 个答案:

答案 0 :(得分:1)

我认为它应该像

一样简单
$result[0]['text']