Hello, Does anyone know who to get the values from a nested hash in
Ruby.
I made the following request which after doing the JSON.parse, it
returns a nested hash with arrays. So, I am trying to figure out how to
access the values in the response. See below for response.
uri =
URI.parse('http://nvillette.dev.targetspot.com/tod.php?station=KRAYFM&length=30&zip=28902')
res = Net::HTTP.get_response(uri)
result= res.body
puts parsed = JSON.parse(result)
Ex. How would I verify that the duration is 30?
Response:
{"TOD":{"version":"1.0","AdBreaks":{"AdBreak":[{"adType":"AUDIO","duration":30,"adCount":1,"Ad":[{"id":611,"acc":225,"lastModified":"2013-03-11T19:22:15","order":1,"adType":"AUDIO","duration":30,"MediaFile":{"uri":"http:\/\/content.dev.targetspot.com\/content\/act\/225\/adunit\/86\/02\/1363029493701178_225.mp3","type":"audio\/mpeg","bitrate":64},"Impression":{"Log":[{"uri":"http:\/\/nvillette.dev.targetspot.com\/log.php?data=VVNFUj00YzRhN2FjZi1jMWIzLTQxMWItOTAzMy1kMTZiMzI0YTM3YzMmU1RBVD1LUkFZRk0mSUQ9NjExJkFDQ09VTlRJRD0yMjUmQURVTklUSUQ9NTEyJlBSPTI1Jk1QUj0yNSZDVD1TMzAmUkVQPTkwMCZaPTI4OTAyJk1BUktFVElEPTUyNCZTVEFURT1OQyZHRU9QUkVGSUQ9MSZSRUdJT05JRD04JkNBQ0hFQlVTVEVSPTEzNjMwMzM2ODcmQk49MyZWPVRPRCZHPTAmQT0xJkk9MCZWSVNVQUxNT0RFPTImRkxBU0hFTkFCTEVEPTAmVEhJUkRQQVJUWVNUQVRVUz0xJlRTQU5BTFlUSUNTPTEmTVN
BPTAmQURTT1VSQ0VTRUxFQ1RFRD0xJkFEU09VUkNFQVRURU1QVEVEJTVCMCU1RD0xJk1FVEhPRD0yJk1PQklMRT0wJlBSRVJPTEw9MCZDTEs9MCZET1dOTE9BRD0wJkNBTExDTElDSz0wJlJBVEVMT0c9MCZJR05PUkVfR0VPX0lQPTAmVFo9QW1lcmljYSUyRk5ld19Zb3JrJkNUQ0Y9LTEmU1RDRj0tMSZDSUNGPS0xJkdNPVpJUCZEUz0wLjAwMDAwMDAwMDAmQURCUkVBSz0zMA==","event":"complete","source":"TargetSpot"}]},"CompanionVisual":{"MediaFile":[{"uri":"http:\/\/content.dev.targetspot.com\/content\/act\/225\/visual\/89\/9f\/180\/135\/1363029483307708_225.jpg","type":"jpg","width":180,"height":135},{"uri":"http:\/\/content.dev.targetspot.com\/content\/act\/225\/visual\/89\/9f\/180\/150\/1363029483307708_225.jpg","type":"jpg","width":180,"height":150},{"uri":"http:\/\/content.dev.targetspot.com\/content\/act\/225\/visual\/89\/9f\/300\/250\/1363029483307708_225.jpg","type":"j
pg","width":300,"height":250},{"uri":"http:\/\/content.dev.targetspot.com\/content\/act\/225\/visual\/89\/9f\/320\/240\/1363029483307708_225.jpg","type":"jpg","width":320,"height":240},{"uri":"http:\/\/content.dev.targetspot.com\/content\/act\/225\/visual\/89\/9f\/336\/280\/1363029483307708_225.jpg","type":"jpg","width":336,"height":280}]}}]}]}}}
···
--
Posted via http://www.ruby-forum.com/.