【问题标题】:Display text from a json decoded array显示来自 json 解码数组的文本
【发布时间】:2014-08-24 06:21:54
【问题描述】:
  Array
(
    [statuses] => Array
        (
            [0] => Array
                (
                    [metadata] => Array
                        (
                            [result_type] => recent
                            [iso_language_code] => en
                        )

                    [created_at] => Thu Jul 03 08:06:24 +0000 2014
                    [id] => 484609084809687043
                    [id_str] => 484609084809687043
                    [text] => RT @RashtrapatiBhvn: #Rains at the #RashtrapatiBhavan http://t.co/w1imlVFbHe
                    [source] => Twitter Web Client
                    [truncated] => 
                    [in_reply_to_status_id] => 
                    [in_reply_to_status_id_str] => 
                    [in_reply_to_user_id] => 
                    [in_reply_to_user_id_str] => 
                    [in_reply_to_screen_name] => 
                    [user] => Array
                        (
                            [id] => 1620882618
                            [id_str] => 1620882618
                            [name] => HinduNationalist#HDL
                            [screen_name] => hinduwarrior15
                            [location] => HINDUSTAN
                            [description] => I want  India to become a exclusive  Hindurashtra. Want a HINDUSTAN by hindus for hindus and to hindus. HINDU NATIONALIST.. #HDL
                            [url] => http://t.co/hWAAfdlWMX
                            [entities] => Array
                                (
                                    [url] => Array
                                        (
                                            [urls] => Array
                                                (
                                                    [0] => Array
                                                        (
                                                            [url] => http://t.co/hWAAfdlWMX
                                                            [expanded_url] => http://www.hdlindia.org/
                                                            [display_url] => hdlindia.org
                                                            [indices] => Array
                                                                (
                                                                    [0] => 0
                                                                    [1] => 22
                                                                )

                                                        )

                                                )

                                        )

这是我调用 Twitter API 得到的典型结果,但我只想显示其中的 id 和文本。我已经使用 json_decode 方法解码了传入的 json 结果。

我从来没有用过json字符串,如果有人能帮忙就太好了

请帮忙

【问题讨论】:

    标签: php json api rest twitter


    【解决方案1】:

    $yourArray['statuses'][0]['id']$yourArray['statuses'][0]['text'] 应该可以解决问题。

    【讨论】:

    • 嘿,谢谢它的工作,但如果我想显示用户数组中的文本,就像我想显示用户 ID 一样
    • 这些都是嵌套数组。尝试了解结构并尽可能深入。 user 数组也是$yourArray['statuses'][0] 的一项。所以如果你想从用户数组中访问id,你需要更深一层:$yourArray['statuses'][0]['user']['id']
    猜你喜欢
    • 1970-01-01
    • 2019-12-28
    • 1970-01-01
    • 2018-09-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-21
    • 2019-02-23
    相关资源
    最近更新 更多