簡體   English   中英

如何在json對象中訪問此鍵? (javascript)

[英]How do I access this key in a json object? (javascript)

我有一個訪問Twitch.tv API的函數來檢索有關實時流的各種信息。 當我嘗試為在線流檢索“游戲”鍵時,它只是返回“未定義”,盡管如果我訪問開發者控制台,我可以看到記錄的json對象包括正確的游戲鍵。 如何正確訪問游戲鑰匙?

屏幕截圖

我的功能:

$("#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> &nbsp; &nbsp; &nbsp; <strong>Status: " + $streamstatus2 + "</strong><br><br>" + $currentgame);

            });

        };
    })
});

你需要使用

json['stream']['game']json.stream.game

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM