0

我在 php 中收到了一个 instagram 响应。

我已经对其进行了 json 解码,但现在是什么。我想访问数据节点并在该节点中执行 foreach。我是 php 新手,我不确定这是什么数据类型或如何操作它。

这是示例响应的 var_dump:

object(stdClass)#142 (3) {
  ["pagination"]=>
  object(stdClass)#143 (6) {
    ["next_max_tag_id"]=>
    string(13) "1376466917514"
    ["deprecation_warning"]=>
    string(94) "next_max_id and min_id are deprecated for this endpoint; use min_tag_id and max_tag_id instead"
    ["next_max_id"]=>
    string(13) "1376466917514"
    ["next_min_id"]=>
    string(13) "1376496264137"
    ["min_tag_id"]=>
    string(13) "1376496264137"
    ["next_url"]=>
    string(119) "https://api.instagram.com/v1/tags/asdf/media/recent?client_id=ea7bee895ef34ed08eacad639f515897&max_tag_id=1376466917514"
  }
  ["meta"]=>
  object(stdClass)#144 (1) {
    ["code"]=>
    int(200)
  }
  ["data"]=>
  array(14) {
    [0]=>
    object(stdClass)#145 (15) {
      ["attribution"]=>
      NULL
      ["videos"]=>
      object(stdClass)#146 (2) {
        ["low_resolution"]=>
        object(stdClass)#147 (3) {
          ["url"]=>
          string(81) "http://distilleryimage2.s3.amazonaws.com/78652d5004c011e3bc3322000ae91126_102.mp4"
          ["width"]=>
          int(480)
          ["height"]=>
          int(480)
        }
        ["standard_resolution"]=>
        object(stdClass)#148 (3) {
          ["url"]=>
          string(81) "http://distilleryimage2.s3.amazonaws.com/78652d5004c011e3bc3322000ae91126_101.mp4"
          ["width"]=>
          int(640)
          ["height"]=>
          int(640)
        }
      }
      ["tags"]=>
      array(3) {
        [0]=>
        string(4) "fail"
        [1]=>
        string(5) "llama"
        [2]=>
        string(4) "asdf"
      }
      ["location"]=>
      NULL
      ["comments"]=>
      object(stdClass)#149 (2) {
        ["count"]=>
        int(1)
        ["data"]=>
        array(1) {
          [0]=>
          object(stdClass)#150 (4) {
            ["created_time"]=>
            string(10) "1376471863"
            ["text"]=>
            string(27) "Movie stars✨✨✨✨"
            ["from"]=>
            object(stdClass)#151 (4) {
              ["username"]=>
              string(9) "exinvader"
              ["profile_picture"]=>
              string(76) "http://images.ak.instagram.com/profiles/profile_40595991_75sq_1343328850.jpg"
              ["id"]=>
              string(8) "40595991"
              ["full_name"]=>
              string(9) "exinvader"
            }
            ["id"]=>
            string(18) "522206299031251817"
          }
        }
      }
      ["filter"]=>
      NULL
      ["created_time"]=>
      string(10) "1376471045"
      ["link"]=>
      string(34) "http://instagram.com/p/c_OZ4duqii/"
      ["likes"]=>
      object(stdClass)#152 (2) {
        ["count"]=>
        int(1)
        ["data"]=>
        array(1) {
          [0]=>
          object(stdClass)#153 (4) {
            ["username"]=>
            string(9) "exinvader"
            ["profile_picture"]=>
            string(76) "http://images.ak.instagram.com/profiles/profile_40595991_75sq_1343328850.jpg"
            ["id"]=>
            string(8) "40595991"
            ["full_name"]=>
            string(9) "exinvader"
          }
        }
      }
      ["images"]=>
      object(stdClass)#154 (3) {
        ["low_resolution"]=>
        object(stdClass)#155 (3) {
          ["url"]=>
          string(79) "http://distilleryimage2.s3.amazonaws.com/78652d5004c011e3bc3322000ae91126_6.jpg"
          ["width"]=>
          int(306)
          ["height"]=>
          int(306)
        }
        ["thumbnail"]=>
        object(stdClass)#156 (3) {
          ["url"]=>
          string(79) "http://distilleryimage2.s3.amazonaws.com/78652d5004c011e3bc3322000ae91126_5.jpg"
          ["width"]=>
          int(150)
          ["height"]=>
          int(150)
        }
        ["standard_resolution"]=>
        object(stdClass)#157 (3) {
          ["url"]=>
          string(79) "http://distilleryimage2.s3.amazonaws.com/78652d5004c011e3bc3322000ae91126_7.jpg"
          ["width"]=>
          int(612)
          ["height"]=>
          int(612)
        }
      }
      ["users_in_photo"]=>
      array(0) {
      }
      ["caption"]=>
      object(stdClass)#158 (4) {
        ["created_time"]=>
        string(10) "1376471063"
        ["text"]=>
        string(49) "Our #fail of #asdf #llama heheheheheh watch it :)"
        ["from"]=>
        object(stdClass)#159 (4) {
          ["username"]=>
          string(13) "niamhthegamer"
          ["profile_picture"]=>
          string(77) "http://images.ak.instagram.com/profiles/profile_207533753_75sq_1373203090.jpg"
          ["id"]=>
          string(9) "207533753"
          ["full_name"]=>
          string(12) "Niamh Carbin"
        }
        ["id"]=>
        string(18) "522199590896315100"
      }
      ["type"]=>
      string(5) "video"
      ["id"]=>
      string(28) "522199433064655010_207533753"
      ["user"]=>
      object(stdClass)#160 (6) {
        ["username"]=>
        string(13) "niamhthegamer"
        ["website"]=>
        string(0) ""
        ["profile_picture"]=>
        string(77) "http://images.ak.instagram.com/profiles/profile_207533753_75sq_1373203090.jpg"
        ["full_name"]=>
        string(12) "Niamh Carbin"
        ["bio"]=>
        string(0) ""
        ["id"]=>
        string(9) "207533753"
      }
    }
    [1]=>
    object(stdClass)#161 (14) {
      ["attribution"]=>
      NULL
      ["tags"]=>
      array(20) {
        [0]=>
        string(5) "ville"
        [1]=>
        string(2) "de"
        [2]=>
        string(3) "zen"
        [3]=>
        string(6) "tomska"
        [4]=>
        string(5) "vient"
        [5]=>
        string(9) "reveiller"
        [6]=>
        string(3) "sun"
        [7]=>
        string(4) "asdf"
        [8]=>
        string(4) "blue"
        [9]=>
        string(10) "tranquille"
        [10]=>
        string(2) "la"
        [11]=>
        string(5) "movie"
        [12]=>
        string(5) "route"
        [13]=>
        string(3) "des"
        [14]=>
        string(7) "courses"
        [15]=>
        string(5) "green"
        [16]=>
        string(3) "sur"
        [17]=>
        string(1) "6"
        [18]=>
        string(6) "orange"
        [19]=>
        string(2) "se"
      }
      ["location"]=>
      NULL
      ["comments"]=>
      object(stdClass)#162 (2) {
        ["count"]=>
        int(0)
        ["data"]=>
        array(0) {
        }
      }
      ["filter"]=>
      string(5) "Amaro"
      ["created_time"]=>
      string(10) "1376469591"
      ["link"]=>
      string(34) "http://instagram.com/p/c_LodpnPzh/"
      ["likes"]=>
      object(stdClass)#163 (2) {
        ["count"]=>
        int(6)
        ["data"]=>
        array(4) {
          [0]=>
          object(stdClass)#164 (4) {
            ["username"]=>
            string(15) "sunshineofparis"
            ["profile_picture"]=>
            string(77) "http://images.ak.instagram.com/profiles/profile_466407041_75sq_1373882342.jpg"
            ["id"]=>
            string(9) "466407041"
            ["full_name"]=>
            string(9) "Damien M."
          }
          [1]=>
          object(stdClass)#165 (4) {
            ["username"]=>
            string(8) "lageek89"
            ["profile_picture"]=>
            string(77) "http://images.ak.instagram.com/profiles/profile_192342817_75sq_1375724622.jpg"
            ["id"]=>
            string(9) "192342817"
            ["full_name"]=>
            string(5) "Laura"
          }
          [2]=>
          object(stdClass)#166 (4) {
            ["username"]=>
            string(13) "the_songsmith"
            ["profile_picture"]=>
            string(75) "http://images.ak.instagram.com/profiles/profile_6151918_75sq_1375076242.jpg"
            ["id"]=>
            string(7) "6151918"
            ["full_name"]=>
            string(12) "Shelby Lynne"
          }
          [3]=>
          object(stdClass)#167 (4) {
            ["username"]=>
            string(14) "juansebastianf"
            ["profile_picture"]=>
            string(75) "http://images.ak.instagram.com/profiles/profile_6296481_75sq_1352230019.jpg"
            ["id"]=>
            string(7) "6296481"
            ["full_name"]=>
            string(14) "Juan Sebastian"
          }
        }
      }
      ["images"]=>
      object(stdClass)#168 (3) {
        ["low_resolution"]=>
        object(stdClass)#169 (3) {
          ["url"]=>
          string(79) "http://distilleryimage5.s3.amazonaws.com/1616f73004bd11e38c0f22000ae80389_6.jpg"
          ["width"]=>
          int(306)
          ["height"]=>
          int(306)
        }
        ["thumbnail"]=>
        object(stdClass)#170 (3) {
          ["url"]=>
          string(79) "http://distilleryimage5.s3.amazonaws.com/1616f73004bd11e38c0f22000ae80389_5.jpg"
          ["width"]=>
          int(150)
          ["height"]=>
          int(150)
        }
        ["standard_resolution"]=>
        object(stdClass)#171 (3) {
          ["url"]=>
          string(79) "http://distilleryimage5.s3.amazonaws.com/1616f73004bd11e38c0f22000ae80389_7.jpg"
          ["width"]=>
          int(612)
          ["height"]=>
          int(612)
        }
      }
      ["users_in_photo"]=>
      array(0) {
      }
      ["caption"]=>
      object(stdClass)#172 (4) {
        ["created_time"]=>
        string(10) "1376469678"
        ["text"]=>
        string(154) "Bonjour le jour :D. #vient #de #se #reveiller #tranquille #zen #asdf #movie song #6 #sur #la #route #des #courses #tomska #sun #green #orange #blue #ville"
        ["from"]=>
        object(stdClass)#173 (4) {
          ["username"]=>
          string(6) "hotoro"
          ["profile_picture"]=>
          string(75) "http://images.ak.instagram.com/profiles/profile_9551854_75sq_1372320657.jpg"
          ["id"]=>
          string(7) "9551854"
          ["full_name"]=>
          string(6) "Jarod~"
        }
        ["id"]=>
        string(18) "522187967261638049"
      }
      ["type"]=>
      string(5) "image"
      ["id"]=>
      string(26) "522187240925625569_9551854"
      ["user"]=>
      object(stdClass)#174 (6) {
        ["username"]=>
        string(6) "hotoro"
        ["website"]=>
        string(0) ""
        ["profile_picture"]=>
        string(75) "http://images.ak.instagram.com/profiles/profile_9551854_75sq_1372320657.jpg"
        ["full_name"]=>
        string(6) "Jarod~"
        ["bio"]=>
        string(0) ""
        ["id"]=>
        string(7) "9551854"
      }
    }
  }
}
4

1 回答 1

1

这是你的foreach

$object = json_decode($response);
foreach ($object->data as $data)
{
    echo $data->filter;
    echo $data->link;
    //etc
}
于 2013-08-14T09:33:01.513 回答