title: Jquery Ajax Json Object
body: <p>Basically I am trying to return a list of names gotten from an Ajax request. When there is only one name, it works perfectly. However with multiple names I start seeing behavior I can't explain.</p>
  
  <pre><code>function getIDFromInput(input){
      sendToID = new Array; //An Array of "Name :Id" 
      $.ajax({
          type:"GET",
          url: "user_search.php",
          contentType:"application/x-www-form-urlencoded; charset=utf-8",
          dataType:"json",
          async:false,    
          data: "q="+input,
          success:function(data){
              if(data.success){
                  var userLength = data.success.length;                   
                  if(userLength == 1){ // For one user everything works fine
                      var userNum = data.success.users[0];                        
                      var userName = data.success.usersNames[userNum];                        
                      sendToID[0] = userName + " :"+userNum;
  
                  }
                  else if(userLength &gt; 1){ // Multiple users it fails
  
                      for(i = 0; i &lt; userLength; i++){
  
                          var userNum = data.success.users[i];
                          //this call works
                          var userName = data.success.usersNames[userNum];
                          //this call fails, even though it seems to be the same call as above
                          sendToID[i] = userName + " :"+userNum;
                      }                       
                  }
                  else if(userLength &lt; 1){ // never enter here
                  }
              }           
          },
          error:function(data){ //After it fails it goes into here
  
          }
      });
      return sendToID;
  }
  </code></pre>
  
  <p>The JSON I am passing back for &lt; 2, ( The one that doesn't work, is below)</p>
  
  <pre><code>{"success":{"length":2,"userNames":[{"5":"Travis Baseler"},{"6":"Ravi Bhalla"}],"users":["5","6"]}}
  </code></pre>
  
  <p>The JSON I am passing back the one that does work is</p>
  
  <pre><code>{"success":{"length":"1","usersNames":{"6":"Ravi Bhalla"},"users":["6"]}}
  </code></pre>
  
  <p>Does anyone know why the first works but the second doesn't?</p>