我有一个函数可以访问Twitch.tv API来检索有关活动流的各种信息。当我试图检索在线流的“游戏”键时,它只是返回“未定义”,尽管如果我访问开发人员控制台,我可以看到记录在案的json对象包含正确的游戏键。如何正确访问游戏密钥?
My函数:
$("#usernamelookupcheck").on("click", function() {
$.getJSON("https://wind-bow.glitch.me/twitch-api/users/" + $("#usernamelookup").val(), function(json) {
if (json["error"] == "Not Found") {
$streamstatus2 = "User does not exist!";
$("#lookupresult").html("User does not exist!");
} else {
$.getJSON("https://wind-bow.glitch.me/twitch-api/streams/" + $("#usernamelookup").val(), function(json) {
$currentgame = json["game"];
if (json["stream"] === null) {
$streamstatus2 = "Offline";
} else {
$streamstatus2 = "Online" + "<br><br>";
console.log(json);
};
$("#lookupresult").html("<br><br> <strong>Status: " + $streamstatus2 + "</strong><br><br>" + $currentgame);
});
};
})
});发布于 2017-07-11 04:37:15
你需要用
json['stream']['game']或json.stream.game
https://stackoverflow.com/questions/45025478
复制相似问题