[英]How can I get my URL to update to different API id's once I've looped through a JSON array?
When I'm looping through my JSON file I'm taking out all the Ids with this forEach loop 当我循环遍历JSON文件时,我使用此forEach循环取出所有ID。
var gameId = request("https://api.sportradar.us/ncaamb-t3/games/" + yyyy + "/" + mm + "/" + dd + "/schedule.json?api_key=************", function(error, response, body){
if(!error && response.statusCode == 200){
var data = JSON.parse(body);
data.games.forEach((v) => {
console.log(v.id);
});
}
});
It gives me the ID's of the information that I want like this 它给我这样我想要的信息的ID
dcb9a3df-a350-4fa3-ba8d-ddb413a5c5df
c4aa937a-0676-4395-856d-5b7e2216027c
91b8cea3-d41d-4269-aac7-b94e4b06d27c
6043b675-64b7-4575-bc0f-1af1502eb366
56083249-a870-40f7-9d86-f221c588d31c
6f0e4992-d5cc-4e40-ba7f-08cf8f801295
a4ca2161-bbcd-4423-8a51-e5886873e78a
1b9cd7bc-8970-4c62-ae72-c03f93cb2c05
21f9601e-db34-4c30-a568-b40f40627e66
0ccb6184-7abc-4035-ad14-6b2c405ee002
7618e36d-4191-4be1-8cdd-61087df2b07b
793e0d40-4f34-462e-ae0c-fde5c0e0aec3
a7da9ccc-80a1-44f8-b8eb-93369f8e8aae
eb02bcae-83f2-4d00-98be-3add44be7c51
a8fd9234-1b37-4b18-abea-f33afcda0ae0
ad536204-057a-4fe6-8f3d-c151018867af
b4c96280-9799-4566-a36e-9c4ac2fb942b
ed0bdb48-3a3b-47f4-b84c-3cdea0122c9e
0a1276d6-0c5d-4c77-9a3c-de6f04a2f342
b9e451c9-e978-40af-b6cf-bcb21f33aec6
c16b8327-5994-45a7-b380-03e1712e6a0c
6a02a4f5-983a-494b-82a8-bd8155256fd8
c0c3061e-814c-4869-ac66-5bbeb8a59830
9a778f37-1010-4625-b715-a7a0222df673
ddcd9846-c8b7-46d5-87c9-526d0431dc13
c75b0bd5-db16-4f8a-81d1-b8e82e7f2dc9
426f3858-a2b0-462c-a72e-57bc5db32a2f
d2cfb022-064b-4fac-ad99-67666ef25a2d
36ced72a-9d6a-47fe-af0b-613f30ac69c0
But then I would like to insert each ID that is returned into a new URL like this: 但是然后我想将返回的每个ID插入新的URL中,如下所示:
request("https://api.sportradar.us/ncaamb-t3/"+ gameId +"/boxscore.json?api_key=***************", function(error, response, body) {
if(!error && response.statusCode == 200){
var data = JSON.parse(body);
var homeName = (data.home.name);
var awayName = (data.away.name);
var homeScore = (data.home.points);
var awayScore = (data.away.points);
if(homeScore > awayScore){
console.log(homeName.toUpperCase() + " WIN!");
}else {
console.log(awayName.toUpperCase() + " WIN!");
}
}
});
I'm using the variable gameId inside of my url like this " https://api.sportradar.us/ncaamb-t3/ "+ gameId +"/boxscore.json?api_key=***************" 我在网址中使用了变量gameId,例如““ https://api.sportradar.us/ncaamb-t3/ ” + gameId +“ / boxscore.json?api_key = ********** *****”
But it's only giving me the id's and not what I'm wanting which is whether or not the team won or not. 但这只是给我身份证,而不是我想要的,这就是车队是否赢了。 Do you guys have any idea what I could be doing wrong? 你们知道我在做什么错吗? I need it to visit two different JSON pages. 我需要它来访问两个不同的JSON页面。
EDIT****** Tried this out but it didn't seem to work, though it also didn't give me any errors. 编辑******对此进行了尝试,但它似乎也没有起作用,尽管它也没有给我任何错误。
request("https://api.sportradar.us/ncaamb-t3/games/" + yyyy + "/" + mm + "/" + dd + "/schedule.json?api_key=j6mu95u99hsaayj5etfuzh6w", function(error, response, body){
if(!error && response.statusCode == 200){
var data = JSON.parse(body);
data.games.forEach((v) => {
request("https://api.sportradar.us/ncaamb-t3/"+ v.id +"/boxscore.json?api_key=j6mu95u99hsaayj5etfuzh6w", function(error, response, body) {
if(!error && response.statusCode == 200){
var data = JSON.parse(body);
var homeName = (data.home.name);
var awayName = (data.away.name);
var homeScore = (data.home.points);
var awayScore = (data.away.points);
if(homeScore > awayScore){
console.log(homeName.toUpperCase() + " WIN!");
}else {
console.log(awayName.toUpperCase() + " WIN!");
}
}
});
});
}
});
When I console.logged it it seems to be working, so I'm not sure why it's not console.logging properly...... 当我进行console.logging时,它似乎可以正常工作,所以我不确定为什么它无法正确进行console.logging ......
792e9eff-cece-49bc-a696-a0632702e96e
https://api.sportradar.us/ncaamb-t3/games/792e9eff-cece-49bc-a696-a0632702e96e/boxscore.json?api_key=*********** function (error, response, body) {
if(!error && response.statusCode == 200){
var homeName = (data.home.name);
var awayName = (data.away.name);
var homeScore = (data.home.points);
var awayScore = (data.away.points);
if(homeScore > awayScore){
console.log(homeName.toUpperCase() + " WIN!");
}else {
console.log(awayName.toUpperCase() + " WIN!");
}
}
}
For the code in your edit-- 对于您编辑中的代码-
v.id is the piece of information you want by the looks of it, so in your second API request, you should be concatenating v.id, not gameId. v.id是您所需的信息,因此,在第二个API请求中,应串联v.id,而不是gameId。
request("https://api.sportradar.us/ncaamb-t3/"+ v.id +"/boxscore.json?api_key=j6mu95u99hsaayj5etfuzh6w", function(error, response, body) {
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.