title: Ruby/Rails - Parse JSON and split object to convert to datetime
body: <p>I have the following code:</p>
  
  <pre><code>page = Net::HTTP.get_response(URI.parse('http://www.enhancetv.com.au/tvguide/rss/melbournerss.php')).body rescue nil
  show_info = Hash.from_xml(page).to_json
  puts show_info
  </code></pre>
  
  <p>Which outputs the following JSON:</p>
  
  <pre><code>{"rss":{"version":"2.0","channel":{"title":"EnhanceTV Melbourne TV Guide ","description":null,"link":"http://www.enhancetv.com.au","lastBuildDate":"Wed, 21 Dec
  2011 10:25:55 1000","generator":"FeedCreator 1.7.2","item":[{"title":"Toasted TV - TEN - 07:00:00 - 21/12/2011","link":"http://www.enhancetv.com.au/tvguide/","d
  escription":"Join the team for the latest in gaming, sport, gadgets, pop culture, movies, music and other seriously fun stuff! Featuring a variety of your favou
  rite cartoons."},{"title":"Totally Wild - TEN - 08:00:00 - 21/12/2011","link":"http://www.enhancetv.com.au/tvguide/","description":"The Totally Wild team brings
   you the latest in action, adventure and wildlife from Australia and around theglobe."},{"title":"Explore: Africa&amp;apos;s Rift Valley - SBS ONE - 19:30:00 - 21/
  12/2011","link":"http://www.enhancetv.com.au/tvguide/","description":"Simon Reeve leads a team of journalists on a spectacular journey down East Africa&amp;apos;s R
  ift Valley. From the tiny country of Djibouti, which is the centre of America&amp;apos;s military presence in Africa, to the wide open plains of Kenya, the team enc
  ounter awe-inspiring landscapes, rich culture and amazing wildlife."}]}}}
  </code></pre>
  
  <p>First of all I'd like to actually be able to loop through each of the items.</p>
  
  <p>This is what I have so far, however it's throwing an error. I'm not entirely sure how to even loop through the parsed JSON properly:</p>
  
  <pre><code>result = JSON.parse(show_info) # convert JSON data to native ruby
  
  result["channel"].each do |a|
      puts a['title']
      puts a['description']
      puts a['link']
  end
  </code></pre>
  
  <p>This gives the following error:</p>
  
  <pre><code>scraper.rb:118:in `&lt;main&gt;': undefined method `each' for "rss":String (NoMethodEr
  ror)
  </code></pre>
  
  <p>I'd then want to be able to do a <code>split</code> on the <code>"title"</code> so I can convert the time and date into a <code>DateTime</code> object to use later.</p>
  
  <p>Thanks in advance.</p>