2013-01-10 53 views
0

有人可以幫我打印這個json解碼數組的「text」值嗎? 我沒有回聲$的obj [「文字」]我得到了一個空白:(打印一個遞歸數組

啊,我做的var_dump,所以編輯後它說,它的1個元素的數組內的20個元素的數組:-) 代碼42次我來到解決方案,因爲真棒Fangel幫助打印文本需要放置以下行: echo $ obj [0] [「text」];

$obj=[ 
     { 
      "created_at":"Mon Sep 03 05:00:30 +0000 2012", 
      "id":242487207418544128, 
      "id_str":"242487207418544128", 
      "text":"Clint, come to the Democratic Convention. We'll get you a coherent speech to read - and we'll even help you comb your hair.", 
      "source":"web", 
      "truncated":false, 
      "in_reply_to_status_id":null, 
      "in_reply_to_status_id_str":null, 
      "in_reply_to_user_id":null, 
      "in_reply_to_user_id_str":null, 
      "in_reply_to_screen_name":null, 
      "user":{ 
      "id":15376626, 
      "id_str":"15376626", 
      "name":"BarrackObama", 
      "screen_name":"BarrackObama", 
      "location":"Washington, D.C.", 
      "url":null, 
      "description":"President of the United States of America", 
      "protected":false, 
      "followers_count":94289, 
      "friends_count":1, 
      "listed_count":577, 
      "created_at":"Thu Jul 10 12:05:37 +0000 2008", 
      "favourites_count":0, 
      "utc_offset":-18000, 
      "time_zone":"Quito", 
      "geo_enabled":false, 
      "verified":false, 
      "statuses_count":106, 
      "lang":"en", 
      "contributors_enabled":false, 
      "is_translator":false, 
      "profile_background_color":"E6EB6F", 
      "profile_background_image_url":"http://a0.twimg.com/profile_background_images/76798997/PresidentialSeal.jpg", 
      "profile_background_image_url_https":"https://si0.twimg.com/profile_background_images/76798997/PresidentialSeal.jpg", 
      "profile_background_tile":false, 
      "profile_image_url":"http://a0.twimg.com/profile_images/56441335/so_normal.jpg", 
      "profile_image_url_https":"https://si0.twimg.com/profile_images/56441335/so_normal.jpg", 
      "profile_link_color":"0FA7FF", 
      "profile_sidebar_border_color":"EAFF08", 
      "profile_sidebar_fill_color":"171CA6", 
      "profile_text_color":"E69407", 
      "profile_use_background_image":true, 
      "default_profile":false, 
      "default_profile_image":false, 
      "following":null, 
      "follow_request_sent":null, 
      "notifications":null 
      }, 
      "geo":null, 
      "coordinates":null, 
      "place":null, 
      "contributors":null, 
      "retweet_count":110, 
      "entities":{ 
      "hashtags":[ 

      ], 
      "urls":[ 

      ], 
      "user_mentions":[ 

      ] 
      }, 
      "favorited":false, 
      "retweeted":false 
     } 
    ] 
+0

它似乎有看二進制文件! –

+0

你在開玩笑嗎?我沒有得到這個笑話?你能澄清嗎? – Gordon

+0

我想這是關於你的JSON的格式。 –

回答

0

這是必經之路打印它:echo $obj[0]["text"];

0

http://php.net/manual/en/function.json-decode.php

ASSOC

爲TRUE時,返回的對象將被轉換成關聯 陣列。

當你設置爲真第二個參數,你應該做的,而不是echo $obj["text"];$obj->text;因爲,它在手動,第二個參數,如果爲true,力json_decode返回即使是在JSON對象關聯數組說。

就我所見,您的JSON中有一個對象數組。所以在json解碼之後,你也應該有一個對象數組。只需使用foreach循環要經過所有項目的排列和打印文本:

foreach($obj as $item) { 
    echo $item->text + "<br/>"; 
} 

或類似這樣的關聯數組(如果json_decode第二個參數是真實的):

foreach($obj as $item) { 
    echo $item["text"] + "<br/>"; 
} 
+0

好吧我沒有完全解決這個問題,你能幫我打印我發佈在編輯 – Gordon

+0

的對象的文本。假設這是你所需要的。至少據我的理解你的問題 –

+0

是的,我猜這就是我需要的,但是我需要等待30分鐘才能得到json的URL。 – Gordon