我搜索过高低,我必须忽略一些明显的东西。如何重新构建我从youtube API检索到的输出,看起来像下面的第二个代码块。另外,我想删除阵列的视频部分。我甚至不知道从哪里开始,或者我会发布我迄今为止尝试过的一些例子。
我还想知道第一个数组的构造与第二个数组的确切术语是什么。
以下是从我们的API调用返回的youtube数组。它只是来自youtube Feed的2个帖子..他们从"项目开始#34;:[数组的一部分。
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",
)
)
)
)
答案 0 :(得分:0)
当然,我忘了解读json的回复......
json_decode($视频);
上面的第一个代码块是json数组,第二个块是解码版本。