【发布时间】:2021-10-12 11:40:11
【问题描述】:
这是我的方法:
function RequestGet(options, url){
fetch(url, options).then(function(response){
return response.json();
}).then(function(value) {
data = JSON.stringify(value)
console.log(data)
}).catch(function() {
console.log("fail")
})
}
function GetUUID(){
data = RequestGet()
uuid = []
data2 = data.results[0].groups
groupLength = data2.length
for (i = 0; i < groupLength; i++){
uuid[i] = data2[i].uuid
}
uuidString = uuid.toString()
console.log(uuidString)
}
我需要 RequestGet 来返回 'data' 的输出(我可以使用 console.log(data) 查看),所以我可以使用下面的 GetUUID 函数中的字典来获取特定的键(键 I' m 寻找的是 uuid)。
我只需要能够将 GET 响应传递给 GetUUID 方法。
目前它返回“未定义”
谢谢。
【问题讨论】:
-
你没有从 RequestGet 返回任何东西。
-
这也不起作用。
function RapidproGet(options, url){ return fetch(url, options).then(function(response){ return response.json(); }).then(function(value) { data = JSON.stringify(value) //console.log(data) return data; }).catch(function() { //console.log("fail") }) }
标签: javascript node.js get