我每个人都在使用节点js来消耗来自另一个api的数据。
你可以看到答案:
"items": [
{
"$ref": "http://sports.core.api.qa.espninfra.starwave.com/v2/sports/basketball/leagues/mens-college-basketball?lang=en"
},
{
"$ref": "http://sports.core.api.qa.espninfra.starwave.com/v2/sports/basketball/leagues/nba?lang=en"
}
]
我需要扩展$ ref网址并从此网址中提取调用信息,例如:
{
$ref": "http://sports.core.api.qa.espninfra.starwave.com/v2/sports/basketball/leagues/mens-college-basketball?lang=en",
"id": "41",
"uid": "s:40~l:41",
"name": "NCAA Men's Basketball",
etc....
}
我不知道如何访问节点js中的$ ref键,以及是否有一些库允许我扩展并从此链接中提取信息。
这是我目前的代码:
function main() {
var initializePromise = initialize('http://www.someurl.com');
initializePromise.then(function(result) {
userDetails = result;
console.log("Initialized user details");
return userDetails.items
}, function(err) {
console.log(err);
}).then(function(result) {
// console.log(result);
result.forEach(function(value){
console.log(value);
//here I need to work with the links in value and extract and print the info
});
})
}
我不确定这是正确的承诺实施,我可以做什么,或者可能是更好的选择?