我是Ruby新手。我在变量''
中有这些数据 [{"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"=>[]}}]
我需要将上述数据中的成员电子邮件发送到struct / hashes数组中。
有人可以帮忙怎么做吗?
谢谢!
答案 0 :(得分:2)
您可以使用map
:
str = [{"clicks"=>"1", "member"=>{"email"=>"abc@gmail.com"}}] #...
emails = str.map { |x| x['member']['email'] }
emails # => ["abc@gmail.com", "dft@gmail.com", "man8@gmail.com", "sub60@gmail.com", "mail@moll.com"]