title: JSON - Cannot read property of undefined
body: <p>I have an issue when trying to get some data from a json.</p>
  
  <p>Usually I have to hardcode the JSON variable I want (ID), such as</p>
  
  <pre><code>success: function (json) {
      alert(json.ID.name);
  }
  </code></pre>
  
  <p>Which works just fine, however I need to make this dynamic as my ID needs to update per request. </p>
  
  <p>When I try the following</p>
  
  <pre><code>success: function (json) {
      // ID is given above and it is working fine
      var userID = ID.replace(" ", "");
      userID = userID.toLowerCase().trim();
      alert(json.userID.name);
      }
  </code></pre>
  
  <p>Doing that gives me an error</p>
  
  <blockquote>
    <p>Uncaught TypeError: Cannot read property 'name' of undefined</p>
  </blockquote>
  
  <p>The userID when alerted gives the same String as ID, but sticking it in the json does not seem to work. Any reason why?</p>
  
  <p>Thanks!</p>
  
  <p>Example (unfortunately I cannot post my API key)</p>
  
  <pre><code>var ID = "";
  ID = $("#theID").val();
  if (ID != "") {
  $.ajax({
      url: 'https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/' + ID + '?api_key=&lt;KEY&gt;',
      type: 'GET',
      dataType: 'json',
      data: {
          //email: $('#sube').val()
      },
      success: function (json) {
          var userID = ID.replace(" ", "");
          userID = userID.toLowerCase().trim();
  
  
          document.getElementById("who").innerHTML = "Who: " + json.userID.name;
          document.getElementById("level").innerHTML = "Level:" + json.userID.id;
          document.getElementById("id").innerHTML = "ID: " + json.userID.summonerLevel;
          document.getElementById("idCall").innerHTML = "Status: SUCCESS";
          document.getElementById("url").innerHTML = "URL: " + 'https://na.api.pvp.net/api/lol/na/v1.4/summoner/by-name/' + userID + '?api_key=&lt;KEY&gt;';
      },
      error: function (XMLHttpRequest, textStatus, errorThrown) {
          alert(textStatus);
          document.getElementById("idCall").innerHTML = "Status: FAILED";
      }
  });
  } else {
      document.getElementById("idCall").innerHTML = "Status: FAILED";
  }
  </code></pre>