ruby array of json object access a value
<p>I have an array of json object called line:    </p>

<pre><code>[{"label":"Name","value":"Bob","identifier":"field2","type":"oneLineText","page":1,"page_name":"Step 1","width":"100%"},{"label":"Email","value":"bob@compagny.com","identifier":"field3","type":"email","page":1,"page_name":"Step 1","width":"100%"},{"label":"Phone Number","value":"","identifier":"field7","type":"oneLineText","page":1,"page_name":"Step 1","width":"100%"},{"label":"Comments","value":"some information about the compagny","identifier":"field5","type":"textarea","page":1,"page_name":"Step 1","width":"100%"}]
</code></pre>

<p>How do i access the value of label comment :<br>
<code>"label":"Comments","value":"some information about the compagny"</code>   </p>

<p>Here is my code:  </p>

<pre><code>data = JSON.parse(line) 
data.each do |key, value|
    puts "#{key}"
    puts "#{key} name: #{value["name"]}"
    puts "#{key} value: #{value["value"]}\n"
    label  = value["name"]
    value = value["value"]
    if (label eq "label") &amp;&amp; (value eq "Comments")
         puts "#{key} value: #{value["value"]}\n"
    end
end     
</code></pre>

<p>I got an error after first object id parsed:      </p>

<pre><code>{"label"=&gt;"Name", "value"=&gt;"Bob", "identifier"=&gt;"field2", "type"=&gt;"oneLineText", "page"=&gt;1, "page_name"=&gt;"Step 1", "width"=&gt;"100%"}
undefined method `[]' for nil:NilClass (NoMethodError)` 
</code></pre>