gpt4 book ai didi

javascript - JSON 未定义或 null

转载 作者:行者123 更新时间:2023-12-03 07:35:28 25 4
gpt4 key购买 nike

我正在尝试访问 API,这是我想要访问的树:

{"19777621": [{
"queue": "RANKED_SOLO_5x5",
"name": "Vladimir's Maulers",
"entries": [{
"leaguePoints": 0,
"isFreshBlood": false,
"isHotStreak": true,
"division": "I",
"isInactive": false,
"isVeteran": false,
"losses": 34,
"playerOrTeamName": "Razdiel",
"playerOrTeamId": "19777621",
"wins": 36
}],
"tier": "PLATINUM"
}]}

我设法做了很多例子,但这是我真的无法弄清楚它是如何工作的,我确信我可以响应正文,但如果我尝试做某事,它会以未定义的空白或对象的形式出现。

<head>
<script src="//code.jquery.com/jquery-1.12.0.min.js"></script>
<script src="/js/json2.js"></script>
<script src="/js/json_parse.js"></script>
</head>
<body>
<script>
$.ajax({
url: 'https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/19777621/entry?api_key=b05c2777-462b-4bcc-ac2a-a3223bb74876',
type: 'GET',
dataType: 'json',
data: {

},
success: function (json) {
document.write("The Result Is:")

JSON_Encoded = json;
JSON_Decoded = JSON.stringify(json);
document.write(JSON_Decoded[19777621].name[0])
document.write(JSON_Decoded[19777621].entries.losses[0])

},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("error getting Summoner data!");
}
});

</script>

我知道我做错了什么,我只是想知道是什么

最佳答案

你可以这样写...

$.ajax({
url: 'https://euw.api.pvp.net/api/lol/euw/v2.5/league/by-summoner/19777621/entry?api_key=b05c2777-462b-4bcc-ac2a-a3223bb74876',
type: 'GET',
dataType: 'json',
data: {

},
success: function (json){
document.write("The Result Is:")

//JSON_Encoded = json;
//JSON_Decoded = JSON.stringify(json);
document.write(json['19777621'][0].name)
document.write(json['19777621'][0].entries[0].losses)

},
error: function (XMLHttpRequest, textStatus, errorThrown) {
alert("error getting Summoner data!");
}
});

关于javascript - JSON 未定义或 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35629362/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com