Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Ruby-如何从具有其他数组和散列的数组中获取值?_Ruby On Rails_Ruby - Fatal编程技术网

Ruby on rails Ruby-如何从具有其他数组和散列的数组中获取值?

Ruby on rails Ruby-如何从具有其他数组和散列的数组中获取值?,ruby-on-rails,ruby,Ruby On Rails,Ruby,我有以下格式的数据: {"values"=> [ {"updateKey"=>"UNIU-16268324-5608633092144111616-SHARE", "updateComments"=>{"_start"=>1, "values"=>[{"comment"=>"Sample test this is mike testing.", "person"=>{"siteStandardProfileRequest"=>{"url"

我有以下格式的数据:

{"values"=>
[
{"updateKey"=>"UNIU-16268324-5608633092144111616-SHARE", 
"updateComments"=>{"_start"=>1, 
"values"=>[{"comment"=>"Sample test this is mike testing.", 
  "person"=>{"siteStandardProfileRequest"=>{"url"=>"http://www.linkedin.com/profile?viewProfile=&key=116654056&authToken=xVLh&authType=name&trk=api*a140290*s148640*"}, 
  "lastName"=>"DeLorenzo", 
  "headline"=>"--", 
  "id"=>"QM86-RIKjb", 
  "pictureUrl"=>"http://media.linkedin.com/mpr/mprx/0_OurBLnHMma92b4U4pecXLq2MuW8aFOo4ywXHLqEbPuNO4sjZtEhUwNOWCFhAkJIq07-WoP4V_Zqg", "firstName"=>"Jennifer", 
  "apiStandardProfileRequest"=>{"url"=>"http://api.linkedin.com/v1/people/QM86-RIKjb",     "headers"=>{"values"=>
[{"name"=>"x-li-auth-token", 
"value"=>"name:xVLh"}], 
"_total"=>1}}}, 
"timestamp"=>1337202768000, 
"sequenceNumber"=>1, 
"id"=>80942976}, 
{"comment"=>"123", 
"person"=>{"siteStandardProfileRequest"=>{"url"=>"http://www.linkedin.com/profile?viewProfile=&key=70292133&authToken=wEAo&authType=name&trk=api*a140290*s148640*"}, "lastName"=>"Kartsovnyk", "headline"=>"Snr Software Developer", "id"=>"7-32mNn-Ob", "pictureUrl"=>"http://media.linkedin.com/mpr/mprx/0_xjj5WPXU6fCjCExLjUa9WA69XWNS
我试图做的是循环使用updateComments并获取该用户的每个“id”属性

以下是我到目前为止的情况:

if linked_in_updates.values.updateComments.is_a?(Hash)   
  linked_in_updates.each { |key, value|
    some_value = key
  }
end
我试图提取hash,它是updateComments,如下所示:linked_in_updates.values.updateComments,但我得到如下错误:

NoMethodError: undefined method `updateComments' for #<Array:0x13228fc20>
NoMethodError:#
知道我做错了什么吗?

试着替换

linked_in_updates.values.updateComments.is_a?(Hash)


使用literal
\n
而不是linebreaks@Michael这会影响我提取值的方式吗?谢谢!你能解释一下为什么语法是values[0]['updateComments']?我不知道它是怎样的二维阵列。如果SO允许,我会接受答案。顺便说一句,我还得到了错误:TypeError:在尝试您的建议后无法将字符串转换为整数。添加
Rails.logger.info linked\u in\u updates.values[0]
before
if linked\u in\u updates.values.updateComments.is\u a?(散列)
然后运行
tail-f log/development.log
实际上这是给出错误的那一行:TypeError:无法将数组转换为字符串:)我刚刚更新了传入的数据。也许这会有所不同。
linked_in_updates.values[0]['updateComments'].is_a?(Hash)