我正在使用ASPJson處理ASP和JSON(它曾經在此前託管http://www.aspjson.com/但該網站已不存在,但我從該網站獲得的代碼位於:https://pastebin.com/LJzikNAT )循環瀏覽Youtube搜索JSON響應
這是我的電話到Youtube - 例如:
https://www.googleapis.com/youtube/v3/search?part=id&q=london&type=video&key=[my_key]
返回該JSON數據:
{
"kind": "youtube#searchListResponse",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/o9DTjpevDXudxmhkLef6i-kAnRE\"",
"nextPageToken": "CAUQAA",
"regionCode": "GB",
"pageInfo": {
"totalResults": 1000000,
"resultsPerPage": 5
},
"items": [
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/Qq093B1iIdU7htjV5jYf2Erqxgk\"",
"id": {
"kind": "youtube#video",
"videoId": "5DniDm9epIY"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/gbHSPn7IT-2OJG19vQZzKKTbG1s\"",
"id": {
"kind": "youtube#video",
"videoId": "Zlu542Tx8Fc"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/KQSQBNAk2ArZd_XrpDOIfiMT0XM\"",
"id": {
"kind": "youtube#video",
"videoId": "2tufxwCyrmE"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/wrbmiGkrH9v_QvtNpoIurXH9YQc\"",
"id": {
"kind": "youtube#video",
"videoId": "1XU8AOZ0Inw"
}
},
{
"kind": "youtube#searchResult",
"etag": "\"m2yskBQFythfE4irbTIeOgYYfBU/2sdAsprKoDKIt8mNVYd8prR8uVA\"",
"id": {
"kind": "youtube#video",
"videoId": "vUO6kYLb6As"
}
}
]
}
這是我的ASP代碼,試圖廁所通過結果號碼:
<!--#INCLUDE file="../dist/asp/c.asp" -->
<!--#INCLUDE file="../dist/asp/aspJSON.asp" -->
<%
my_api = "my_key"
sendstring1 = "https://www.googleapis.com/youtube/v3/search?part=id&q=chester&type=video&key="&my_api&""
Set objXML = Server.CreateObject("MSXML2.ServerXMLHTTP")
objXML.Open "GET", sendstring1 , false
objXML.Send()
BackFromGoogle1 = objXML.responseText
Set oJSON = New aspJSON
oJSON.loadJSON(BackFromGoogle1)
For Each result In oJSON.data("items")
Set this = oJSON.data("items").item(thingy)
var_id = this.item("id").item("videoId")
embed_code = "<iframe width='800' height='450' src='https://www.youtube.com/embed/"&var_id&"?rel=0&wmode=opaque' frameborder='0' allowfullscreen></iframe>"
response.write embed_code
Next
%>
麻煩的是,因爲我遍歷它的ID在var_id
變量返回總是5DniDm9epIY
,這是第一視頻的ID - 它似乎並沒有被改變每次通過循環,我不知道爲什麼?
var_id
顯示5次,因此代碼可以看到「items」集合中有5個註釋,但它並不是每次都通過循環轉到下一個節點。
[使用VBScript訪問JSON數據的所有值]的可能的複製(http://stackoverflow.com/questions/41610139/using-vbscript-to-access-all-values-in-json -data) – Lankymart