如何重新格式化这个数组?



我已经到处找了,我一定忽略了一些明显的东西。如何重建从youtube API检索到的输出,使其看起来像下面的第二个代码块?我还想删除数组的视频部分。我甚至不知道从哪里开始,或者我会张贴一些我到目前为止尝试过的例子。

我还想知道第一个数组和第二个数组是如何构造的确切术语是什么。

这是从我们的API调用返回的youtube数组。这只是youtube上的两个帖子…它们从数组的"items":[部分开始。

Array
(
    [videos] => {
 "kind": "youtube#playlistItemListResponse",
 "etag": ""I_8xdZu766_FSaexEaDXTIfEWc0/qYy5QZyPpmtNPAJ_cTTDagaLYv0"",
 "nextPageToken": "CAIQAA",
 "pageInfo": {
  "totalResults": 15,
  "resultsPerPage": 2
 },
 "items": [
  {
   "kind": "youtube#playlistItem",
   "etag": ""I_8xdZu766_FSaexEaDXTIfEWc0/o2RZKiVOV3D5PlBUVONXwxRQACQ"",
   "id": "VVUtU1dDTm1QOS11ODFLOC1GMkY5RlB3LmJITEwxTDlFX0pB",
   "snippet": {
    "publishedAt": "2015-09-23T21:52:41.000Z",
    "channelId": "UC-SWCNmP9-u81K8-F2F9FPw",
    "title": "A day in the life of a sponsored skateboarder / parent",
    "description": "I've had a hard time connecting with my family lately.",
    "thumbnails": {
     "standard": {
      "url": "https://i.ytimg.com/vi/bHLL1L9E_JA/sddefault.jpg",
      "width": 640,
      "height": 480
     }
    },
    "channelTitle": "Tony Hawk",
    "playlistId": "UU-SWCNmP9-u81K8-F2F9FPw",
    "position": 0,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "bHLL1L9E_JA"
    }
   }
  },
  {
   "kind": "youtube#playlistItem",
   "etag": ""I_8xdZu766_FSaexEaDXTIfEWc0/tFkAXp2IF-WC4lWu_OsWEF4mLIk"",
   "id": "VVUtU1dDTm1QOS11ODFLOC1GMkY5RlB3LkwzdHZvTnBBc25J",
   "snippet": {
    "publishedAt": "2015-01-05T05:13:22.000Z",
    "channelId": "UC-SWCNmP9-u81K8-F2F9FPw",
    "title": "Tahitian treats",
    "description": "",
    "thumbnails": {
     "standard": {
      "url": "https://i.ytimg.com/vi/L3tvoNpAsnI/sddefault.jpg",
      "width": 640,
      "height": 480
     }
    },
    "channelTitle": "Tony Hawk",
    "playlistId": "UU-SWCNmP9-u81K8-F2F9FPw",
    "position": 1,
    "resourceId": {
     "kind": "youtube#video",
     "videoId": "L3tvoNpAsnI"
    }
   }
  }
 ]
}
)

我想重新格式化它,使它看起来更像这样。我只添加了几个字段,以便重新输入它们。希望大家理解了基本思想。

Array
(
 [data] => Array
        (
      [0] => stdClass Object
          (
             [kind] => "youtube#playlistItem",
             [etag] => ""I_8xdZu766_FSaexEaDXTIfEWc0/o2RZKiVOV3D5PlBUVONXwxRQACQ"",
             [id] => "VVUtU1dDTm1QOS11ODFLOC1GMkY5RlB3LmJITEwxTDlFX0pB",
             [snippet] => (
                [publishedAt] =>  "2015-09-23T21:52:41.000Z",
                [channelId] =>  "UC-SWCNmP9-u81K8-F2F9FPw",
              )
           )
      [1] => stdClass Object
          (
             [kind] => "youtube#playlistItem",
             [etag] => ""I_8xdZu766_FSaexEaDXTIfEWc0/o2RZKiVOV3D5PlBUVONXwxRQACQ"",
             [id] => "VVUtU1dDTm1QOS11ODFLOC1GMkY5RlB3LmJITEwxTDlFX0pB",
             [snippet] => (
                [publishedAt] =>  "2015-09-23T21:52:41.000Z",
                [channelId] =>  "UC-SWCNmP9-u81K8-F2F9FPw",
              )
           )
       )
)

当然,我忘了解码json响应…

json_decode(视频)美元;

上面的第一个代码块是json数组,第二个代码块是解码后的版本。

相关内容

  • 没有找到相关文章

最新更新