From: Nicole Villette Date: 2013-03-13T01:41:05+09:00 Subject: Re: Access values for JSON.parse response tamouse mailing lists wrote in post #1101156: > On Mar 11, 2013 4:16 PM, "Matthew Kerwin" wrote: >> >> parsed['TOD']['AdBreaks']['AdBreak'][0]['duration'] >> # or >> parsed['TOD']['AdBreaks']['AdBreak'].select{|ad| >> ad['duration'] == 30 } >> >> Also note: this is yucky. Yucky yucky yucky. A saner person might use >> some local variables. Even one will help a lot: >> >> adbreaks = parsed['TOD']['AdBreaks']['AdBreak'] >> # while I'm here: why does 'AdBreaks' hold one item, >> # but 'AdBreak' hold an array? Odd. > > These are the vagaries of XML :) I have another question. By looking at my response, I am trying to go deeper to access this value: "Impression":{"Log":[{"uri" I am attempting to do the following: uri= parsed['TOD']['AdBreaks']['AdBreak'][0]['Ad'][0]['MediaFile']['Impression']['Log'][0]['uri'] but it does not work. I get the following: NoMethodError: undefined method `[]' for nil:NilClass This seems to work fine, which is a level above: bitrate=parsed['TOD']['AdBreaks']['AdBreak'][0]['Ad'][0]['MediaFile']['bitrate'] Thanks -- Posted via http://www.ruby-forum.com/.