weixin_33726318 2016-02-25 13:57 采纳率: 0%
浏览 25

JSON未定义或为空

Im trying to access a API and heres the tree i want to access:

{"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"
}]}

I managed to do a lot of examples but this is the one i really cant figure out how it works, im sure i can the response body but if i try to do something it comes as undefined blank or Object.

<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>

I know im doing something wrong i just wanted to know what

  • 写回答

1条回答 默认 最新

  • weixin_33697898 2016-02-25 14:25
    关注

    You could write it in this way ...

    $.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!");
    }
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 请问GPT语言模型怎么训练?
  • ¥15 已知平面坐标系(非直角坐标系)内三个点的坐标,反求两坐标轴的夹角
  • ¥15 webots有问题,无响应
  • ¥15 数据量少可以用MK趋势分析吗
  • ¥15 使用VH6501干扰RTR位,CANoe上显示的错误帧不足32个就进入bus off快慢恢复,为什么?
  • ¥15 大智慧怎么编写一个选股程序
  • ¥100 python 调用 cgps 命令获取 实时位置信息
  • ¥15 两台交换机分别是trunk接口和access接口为何无法通信,通信过程是如何?
  • ¥15 C语言使用vscode编码错误
  • ¥15 用KSV5转成本时,如何不生成那笔中间凭证