title: Why do I get "no implicit conversion of String into Integer (TypeError)"?
body: <p>I have some code which I run in very similar circumstances. This is the first circumstance, where I have an <code>imdb_id</code> of a film I want details of:</p>
  
  <pre><code>url = "http://mymovieapi.com/?id=#{self.imdb_id}&amp;type=json&amp;plot=none&amp;episode=0&amp;lang=en-US&amp;aka=simple&amp;release=simple&amp;business=0&amp;tech=0"
  doc = Hpricot(open(url)).to_s
  json = JSON.parse(doc)
  
  puts json
  puts json["imdb_id"]
  </code></pre>
  
  <p>And this gives the following result:</p>
  
  <pre><code>{"rating_count"=&gt;493949,
  "genres"=&gt;["Drama", "Romance"],
  "rated"=&gt;"PG-13",
  "language"=&gt;["English", "French", "German", "Swedish", "Italian", "Russian"],
  "rating"=&gt;7.6,
  "country"=&gt;["USA"],
  "release_date"=&gt;19980403,
  "title"=&gt;"Titanic",
  "year"=&gt;1997,
  "filming_locations"=&gt;"Santa Clarita, California, USA",
  "imdb_id"=&gt;"tt0120338",
  "directors"=&gt;["James Cameron"],
  "writers"=&gt;["James Cameron"],
  "actors"=&gt;["Leonardo DiCaprio", "Kate Winslet", "Billy Zane", "Kathy Bates", "Frances Fisher", "Gloria Stuart", "Bill Paxton", "Bernard Hill", "David Warner", "Victor Garber", "Jonathan Hyde", "Suzy Amis", "Lewis Abernathy", "Nicholas Cascone", "Anatoly M. Sagalevitch"],
  "also_known_as"=&gt;["Tai tan ni ke hao"],
  "poster"=&gt;{"imdb"=&gt;"http://ia.media-imdb.com/images/M/MV5BMjExNzM0NDM0N15BMl5BanBnXkFtZTcwMzkxOTUwNw@@._V1_SY317_CR0,0,214,317_.jpg", "cover"=&gt;"http://imdb-poster.b0.upaiyun.com/000/120/338.jpg!cover?_upt=66ac07591382594194"},
  "runtime"=&gt;["194 min"],
  "type"=&gt;"M",
  "imdb_url"=&gt;"http://www.imdb.com/title/tt0120338/"}
  
  tt0120338
  </code></pre>
  
  <p>This is as expected. In the second circumstance, I have the <code>title</code> and <code>year</code> of the same film:</p>
  
  <pre><code>url = "http://mymovieapi.com/?title=#{self.title}&amp;type=json&amp;plot=simple&amp;episode=0&amp;limit=1&amp;year=#{self.year}&amp;yg=1&amp;mt=none&amp;lang=en-US&amp;offset=&amp;aka=simple&amp;release=simple&amp;business=0&amp;tech=0"
  doc = Hpricot(open(url)).to_s
  json = JSON.parse(doc)
  
  puts json
  puts json["imdb_id"]
  </code></pre>
  
  <p>From this, I get the exact same JSON output:</p>
  
  <pre><code>{"rating_count"=&gt;493949,
  "genres"=&gt;["Drama", "Romance"],
  "rated"=&gt;"PG-13", "language"=&gt;["English", "French", "German", "Swedish", "Italian", "Russian"],
  "rating"=&gt;7.6,
  "country"=&gt;["USA"],
  "release_date"=&gt;19980403,
  "title"=&gt;"Titanic",
  "year"=&gt;1997,
  "filming_locations"=&gt;"Santa Clarita, California, USA",
  "imdb_id"=&gt;"tt0120338",
  "directors"=&gt;["James Cameron"],
  "writers"=&gt;["James Cameron"],
  "actors"=&gt;["Leonardo DiCaprio", "Kate Winslet", "Billy Zane", "Kathy Bates", "Frances Fisher", "Gloria Stuart", "Bill Paxton", "Bernard Hill", "David Warner", "Victor Garber", "Jonathan Hyde", "Suzy Amis", "Lewis Abernathy", "Nicholas Cascone", "Anatoly M. Sagalevitch"],
  "also_known_as"=&gt;["Tai tan ni ke hao"],
  "poster"=&gt;{"imdb"=&gt;"http://ia.media-imdb.com/images/M/MV5BMjExNzM0NDM0N15BMl5BanBnXkFtZTcwMzkxOTUwNw@@._V1_SY317_CR0,0,214,317_.jpg",
  "cover"=&gt;"http://imdb-poster.b0.upaiyun.com/000/120/338.jpg!cover?_upt=ec8bdec31382594417"},
  "runtime"=&gt;["194 min"],
  "type"=&gt;"M",
  "imdb_url"=&gt;"http://www.imdb.com/title/tt0120338/"}
  </code></pre>
  
  <p>But when I try and call <code>puts json["imdb_id"]</code>, I get this error:</p>
  
  <pre><code>no implicit conversion of String into Integer (TypeError)
  </code></pre>
  
  <p>This always happens when fetching using the <code>title</code> and <code>year</code>, yet it seems unexplained as the JSON output is exactly the same.</p>