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 我需要在PC端 开两个抖店工作台客户端.(语言-java)
    • ¥15 有没有哪位厉害的人可以用C#可视化呀
    • ¥15 可以帮我看看代码哪里错了吗
    • ¥15 设计一个成绩管理系统
    • ¥15 PCL注册的选点等函数如何取消注册
    • ¥15 问一下各位,为什么我用蓝牙直接发送模拟输入的数据,接收端显示乱码呢,米思齐软件上usb串口显示正常的字符串呢?
    • ¥15 Python爬虫程序
    • ¥15 crypto 这种的应该怎么找flag?
    • ¥15 代码已写好,求帮我指出错误,有偿!
    • ¥15 matlab+波形匹配算法