Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/ruby/24.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:如何在stuct/hash数组中获取数据?_Ruby_Arrays - Fatal编程技术网

Ruby:如何在stuct/hash数组中获取数据?

Ruby:如何在stuct/hash数组中获取数据?,ruby,arrays,Ruby,Arrays,我对Ruby是新手。我在变量“”中有此数据 我需要将上述数据中的成员电子邮件放入结构/哈希数组 有人能帮忙做这件事吗 谢谢大家! 您可以这样使用: str=[{“单击”=>“1”,“成员”=>{“电子邮件”=>”abc@gmail.com"}}] #... emails=str.map{| x | x['member']['email']} 电子邮件#=>[”abc@gmail.com", "dft@gmail.com", "man8@gmail.com", "sub60@gmail.com",

我对Ruby是新手。我在变量“”中有此数据

我需要将上述数据中的成员电子邮件放入结构/哈希数组

有人能帮忙做这件事吗

谢谢大家!

您可以这样使用:

str=[{“单击”=>“1”,“成员”=>{“电子邮件”=>”abc@gmail.com"}}] #...
emails=str.map{| x | x['member']['email']}
电子邮件#=>[”abc@gmail.com", "dft@gmail.com", "man8@gmail.com", "sub60@gmail.com", "mail@moll.com"]

能否提供所需的结果结构/哈希的示例?另外,到目前为止,您编写了哪些代码来尝试解决这个问题?请把它也贴出来。
 [{"clicks"=>"1", "member"=>{"email"=>"abc@gmail.com", "id"=>"f6d02be6", "euid"=>"f02be6", "email_type"=>"html", "ip_signup"=>nil, "timestamp_signup"=>nil, "ip_opt"=>nil, "timestamp_opt"=>"2013-05-29 09:52:53", "member_rating"=>4, "info_changed"=>"2013-06-06 20:21:44", "web_id"=>"3224865", "leid"=>"3223865", "language"=>"en", "list_id"=>"65d3015", "list_name"=>"XYZ User", "merges"=>{"EMAIL"=>"abc@gmail.com", "FNAME"=>"abc", "LNAME"=>"", "MMERGE3"=>"2", "MMERGE4"=>"ssssssus", "MMERGE5"=>"2", "MMERGE6"=>"0"}, "status"=>"subscribed", "timestamp"=>"2013-05-29 09:52:53", "is_gmonkey"=>false, "lists"=>[{"id"=>"38561f6834", "status"=>"unsubscribed"}], "geo"=>{"latitude"=>"13.000", "longitude"=>"83.000", "gmtoff"=>"6", "dstoff"=>"6", "timezone"=>"Asia/Dhaka", "cc"=>"IN", "region"=>"MH"}, "clients"=>[], "static_segments"=>[], "notes"=>[]}}, {"clicks"=>"1", "member"=>{"email"=>"dft@gmail.com", "id"=>"336ed115c4", "euid"=>"3365c4", "email_type"=>"html", "ip_signup"=>nil, "timestamp_signup"=>nil, "ip_opt"=>nil, "timestamp_opt"=>"2013-05-29 09:52:53", "member_rating"=>4, "info_changed"=>"2013-06-06 20:21:44", "web_id"=>"34877", "leid"=>"14877", "language"=>"en", "list_id"=>"6043215", "list_name"=>"XYZ User", "merges"=>{"EMAIL"=>"dft@gmail.com", "FNAME"=>"asafsadf", "LNAME"=>"", "MMERGE3"=>"6", "MMERGE4"=>"Faires", "MMERGE5"=>"6", "MMERGE6"=>"0"}, "status"=>"subscribed", "timestamp"=>"2013-05-29 09:52:53", "is_gmonkey"=>false, "lists"=>[{"id"=>"386834", "status"=>"unsubscribed"}], "geo"=>{"latitude"=>"20.5188000", "longitude"=>"77.8807000", "gmtoff"=>"6", "dstoff"=>"6", "timezone"=>"Asia/Dhaka", "cc"=>"IN", "region"=>"MH"}, "clients"=>[], "static_segments"=>[], "notes"=>[]}}, {"clicks"=>"2", "member"=>{"email"=>"man8@gmail.com", "id"=>"334a7f", "euid"=>"334617", "email_type"=>"html", "ip_signup"=>nil, "timestamp_signup"=>nil, "ip_opt"=>nil, "timestamp_opt"=>"2013-05-29 09:52:54", "member_rating"=>4, "info_changed"=>"2013-06-06 20:21:46", "web_id"=>"377", "leid"=>"377", "language"=>"en", "list_id"=>"65d3043215", "list_name"=>"XYZ User", "merges"=>{"EMAIL"=>"man8@gmail.com", "FNAME"=>"asafsdf", "LNAME"=>"", "MMERGE3"=>"18", "MMERGE4"=>"TrickTreats", "MMERGE5"=>"18", "MMERGE6"=>"0"}, "status"=>"subscribed", "timestamp"=>"2013-05-29 09:52:54", "is_gmonkey"=>false, "lists"=>[{"id"=>"1f6834", "status"=>"unsubscribed"}], "geo"=>[], "clients"=>[], "static_segments"=>[], "notes"=>[]}}, {"clicks"=>"1", "member"=>{"email"=>"sub60@gmail.com", "id"=>"4e9b7", "euid"=>"4e9b7", "email_type"=>"html", "ip_signup"=>nil, "timestamp_signup"=>nil, "ip_opt"=>nil, "timestamp_opt"=>"2013-05-29 09:52:52", "member_rating"=>4, "info_changed"=>"2013-06-06 20:21:44", "web_id"=>"4605", "leid"=>"4605", "language"=>"en", "list_id"=>"65d3043215", "list_name"=>"XYZ User", "merges"=>{"EMAIL"=>"sub60@gmail.com", "FNAME"=>"Suboohi", "LNAME"=>"", "MMERGE3"=>"1", "MMERGE4"=>"-", "MMERGE5"=>"1", "MMERGE6"=>"0"}, "status"=>"subscribed", "timestamp"=>"2013-05-29 09:52:52", "is_gmonkey"=>false, "lists"=>[{"id"=>"f6834", "status"=>"unsubscribed"}], "geo"=>{"latitude"=>"14.8500000", "longitude"=>"88.0330000", "gmtoff"=>"6", "dstoff"=>"6", "timezone"=>"Asia/Kolkata", "cc"=>"PK", "region"=>"SD"}, "clients"=>[], "static_segments"=>[], "notes"=>[]}}, {"clicks"=>"1", "member"=>{"email"=>"mail@moll.com", "id"=>"083fd3", "euid"=>"083fd3", "email_type"=>"html", "ip_signup"=>nil, "timestamp_signup"=>nil, "ip_opt"=>nil, "timestamp_opt"=>"2013-05-29 09:52:52", "member_rating"=>4, "info_changed"=>"2013-06-06 20:21:44", "web_id"=>"314649", "leid"=>"314649", "language"=>"en", "list_id"=>"43215", "list_name"=>"XYZ User", "merges"=>{"EMAIL"=>"mail@mollysfarmmade.com", "FNAME"=>"Susan", "LNAME"=>"", "MMERGE3"=>"2", "MMERGE4"=>"kles", "MMERGE5"=>"2", "MMERGE6"=>"0"}, "status"=>"subscribed", "timestamp"=>"2013-05-29 09:52:52", "is_gmonkey"=>false, "lists"=>[{"id"=>"386834", "status"=>"unsubscribed"}], "geo"=>{"latitude"=>"22.9706000", "longitude"=>"87.6002000", "gmtoff"=>"6", "dstoff"=>"6", "timezone"=>"Asia/Kolkata", "cc"=>"IN", "region"=>"KA"}, "clients"=>[], "static_segments"=>[], "notes"=>[]}}]