【发布时间】:2011-08-26 23:06:39
【问题描述】:
大家好,从 Twitter 返回的 JSON 中访问元素时遇到问题。我试图从 6 个不同的帐户中检索大约 18 条推文并按时间顺序显示它们,但我不知道如何访问数组中的元素。我尝试过使用json_decode(),尝试过foreach 循环和for 循环。基本上我在以下所有内容中,我只需要以下元素:text、user->screen_name、user->profile_image_url 和 created_at。原因是当我将 php 上传到网站时,我正在构建的应用程序超时并且没有收到数据,所以我试图通过只取回所需的内容来使回报更小。任何人,这是我收到的 1 条推文的样本......
[{"in_reply_to_status_id":null,"created_at":"Thu Aug 25 01:50:07 +0000 2011","geo":null,"user":{"profile_background_tile":true,"protected":false,"url":"http:\/\/www.backpocketmemory.com","name":"Back Pocket Memory","default_profile":false,"friends_count":1115,"profile_link_color":"0084B4","default_profile_image":false,"show_all_inline_media":false,"contributors_enabled":false,"following":false,"geo_enabled":false,"utc_offset":-28800,"profile_sidebar_border_color":"C0DEED","description":"We're a hard rock\/pop band from Burbank, CA. We love you. facebook.com\/backpocketmemory @bpmchris @bpmguitar @bpmsixstring @bpmbass @bpmdrummer\r\n","profile_background_image_url_https":"https:\/\/si0.twimg.com\/profile_background_images\/236635469\/60509_430737311786_16094846786_5566606_2050188_n.jpg","time_zone":"Pacific Time (US & Canada)","created_at":"Mon Jul 27 20:58:35 +0000 2009","profile_image_url":"http:\/\/a2.twimg.com\/profile_images\/1320311803\/STICKER_IDEA_1_normal.jpg","is_translator":false,"profile_use_background_image":true,"profile_image_url_https":"https:\/\/si0.twimg.com\/profile_images\/1320311803\/STICKER_IDEA_1_normal.jpg","follow_request_sent":false,"statuses_count":2238,"profile_background_color":"C0DEED","screen_name":"bckpcktmmry","profile_background_image_url":"http:\/\/a3.twimg.com\/profile_background_images\/236635469\/60509_430737311786_16094846786_5566606_2050188_n.jpg","favourites_count":6,"id_str":"60708421","lang":"en","verified":false,"profile_text_color":"333333","location":"Burbank, CA","id":60708421,"listed_count":19,"notifications":false,"profile_sidebar_fill_color":"DDEEF6","followers_count":683},"in_reply_to_user_id":null,"truncated":false,"coordinates":null,"favorited":false,"possibly_sensitive":false,"in_reply_to_status_id_str":null,"in_reply_to_screen_name":null,"source":"\u003Ca href=\"http:\/\/www.facebook.com\/twitter\" rel=\"nofollow\"\u003EFacebook\u003C\/a\u003E","in_reply_to_user_id_str":null,"id_str":"106543849266098176","id":106543849266098176,"contributors":null,"place":null,"retweeted":false,"retweet_count":2,"text":"Want to pick up tix for Rob's Bday Show next week? Come visit us at rehearsal. 156 W Providencia in Burbank.... http:\/\/t.co\/oNvw5I6"}]
感谢任何帮助!
【问题讨论】:
-
您能在某处发布更完整的示例吗?
-
编辑了 OP 以在 JSON 的末尾添加“]”,但在我粘贴时没有出现。 @sberry2A 更完整的示例,我的 PHP 代码或 JSON 返回什么?