JSON字符串上未定义的返回值

时间:2015-07-11 01:20:58

标签: javascript json

我想知道是否有人能够解释为什么我的所有JSON都以Undefined的形式返回.. json的问题是这个

nav

和我必须完成的Javascript是:

注意:在提供的代码中,i / sumID是273746,s是' oce'由于Riot API指南,我无法为您提供API的直接链接,因此我必须将其粘贴到上面。

function statsLookUp(i,s){

{"273746":[{"name":"Darius's Wizards","tier":"GOLD","queue":"RANKED_SOLO_5x5","entries":[{"playerOrTeamId":"273746","playerOrTeamName":"Magnanimous","division":"V","leaguePoints":0,"wins":19,"losses":15,"isHotStreak":false,"isVeteran":false,"isFreshBlood":false,"isInactive":false}]}]}

一切都继续以未定义的方式返回,但我似乎无法找到问题所在:/

1 个答案:

答案 0 :(得分:0)

只需进行此更改,您的代码就可以了:

leagueName = json[sumID][0].name;
leagueTier = json[sumID][0].tier;
leagueDiv  = json[sumID][0].entries[0].division;
leagueLoss = json[sumID][0].entries[0].losses;
leagueWin  = json[sumID][0].entries[0].wins;

这是您的格式化JSON数据:

{
   "273746":[
      {
         "name":"Darius's Wizards",
         "tier":"GOLD",
         "queue":"RANKED_SOLO_5x5",
         "entries":[
            {
               "playerOrTeamId":"273746",
               "playerOrTeamName":"Magnanimous",
               "division":"V",
               "leaguePoints":0,
               "wins":19,
               "losses":15,
               "isHotStreak":false,
               "isVeteran":false,
               "isFreshBlood":false,
               "isInactive":false
            }
         ]
      }
   ]
}

我希望这会有所帮助。