[英]How do I access this key in a json object? (javascript)
I have a function that accesses the Twitch.tv API to retrieve various information about a live stream. 我有一个访问Twitch.tv API的函数来检索有关实时流的各种信息。 When I try to retrieve the "game" key for a stream which is online it simply returns "undefined", although if I access the developer console I can see the logged json object includes the proper game key. 当我尝试为在线流检索“游戏”键时,它只是返回“未定义”,尽管如果我访问开发者控制台,我可以看到记录的json对象包括正确的游戏键。 How do I properly access the game key? 如何正确访问游戏钥匙?
My function: 我的功能:
$("#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);
});
};
})
});
you need to use 你需要使用
json['stream']['game']
or json.stream.game
json['stream']['game']
或json.stream.game
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.