2013-04-10 104 views
2

如何从这个哈希删除评论和评论计数。我需要没有评论的数据。如何删除评论和评论从这个哈希计数

{"id"=>"149536368430_10151515647758431", "from"=>{"category"=>"Product/service", "name"=>"Swiffer", "id"=>"149536368430"}, "to"=>{"data"=>[{"category"=>"Media/news/publishing", "name"=>"Hispanicize", "id"=>"119781464743025"}, {"category"=>"Household supplies", "name"=>"P&G everyday", "id"=>"142671152446083"}]}, "message"=>"Swiffer will be at Hispanicize in Miami Wednesday-Saturday this week. If you are attending, come dust with us at the P&G everyday Lounge and take the Abuelita Test (or Grandmother Test!)", "message_tags"=>{"19"=>[{"id"=>"119781464743025", "name"=>"Hispanicize", "type"=>"page", "offset"=>19, "length"=>11}], "117"=>[{"id"=>"142671152446083", "name"=>"P&G everyday", "type"=>"page", "offset"=>117, "length"=>12}]}, "picture"=>"http://photos-d.ak.fbcdn.net/hphotos-ak-ash3/155668_10151515647728431_245572821_s.png", "link"=>"http://www.facebook.com/photo.php?fbid=10151515647728431&set=a.186758558430.126763.149536368430&type=1&relevant_count=1", "icon"=>"http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif", "actions"=>[{"name"=>"Comment", "link"=>"http://www.facebook.com/149536368430/posts/10151515647758431"}, {"name"=>"Like", "link"=>"http://www.facebook.com/149536368430/posts/10151515647758431"}], "privacy"=>{"value"=>""}, "type"=>"photo", "status_type"=>"added_photos", "object_id"=>"10151515647728431", "created_time"=>"2013-04-08T18:03:01+0000", "updated_time"=>"2013-04-08T18:22:37+0000", "shares"=>{"count"=>1}, "likes"=>{"data"=>[{"name"=>"Penny Denton", "id"=>"100000188001574"}, {"name"=>"Angie Altman", "id"=>"100002250974930"}, {"name"=>"Jeannise R. Clagett", "id"=>"100002279556425"}, {"name"=>"Andy Tappan", "id"=>"100000485732671"}], "count"=>128}, "comments"=>{"data"=>[{"id"=>"149536368430_10151515647758431_9285816", "from"=>{"name"=>"Melissa Rivera", "id"=>"600150684"}, "message"=>"Thats cute!! Love the idea!! :)", "created_time"=>"April 08 at 06:22PM"}], "count"=>4}, "publishedDate"=>"2013-04-08 18:22:37", "source"=>"fb"} 

任何帮助???我会非常感谢!

回答

3
my_hash = {"id"=>"149536368430_10151515647758431", "from"=>{"category"=>"Product/service", "name"=>"Swiffer", "id"=>"149536368430"}, "to"=>{"data"=>[{"category"=>"Media/news/publishing", "name"=>"Hispanicize", "id"=>"119781464743025"}, {"category"=>"Household supplies", "name"=>"P&G everyday", "id"=>"142671152446083"}]}, "message"=>"Swiffer will be at Hispanicize in Miami Wednesday-Saturday this week. If you are attending, come dust with us at the P&G everyday Lounge and take the Abuelita Test (or Grandmother Test!)", "message_tags"=>{"19"=>[{"id"=>"119781464743025", "name"=>"Hispanicize", "type"=>"page", "offset"=>19, "length"=>11}], "117"=>[{"id"=>"142671152446083", "name"=>"P&G everyday", "type"=>"page", "offset"=>117, "length"=>12}]}, "picture"=>"http://photos-d.ak.fbcdn.net/hphotos-ak-ash3/155668_10151515647728431_245572821_s.png", "link"=>"http://www.facebook.com/photo.php?fbid=10151515647728431&set=a.186758558430.126763.149536368430&type=1&relevant_count=1", "icon"=>"http://static.ak.fbcdn.net/rsrc.php/v2/yz/r/StEh3RhPvjk.gif", "actions"=>[{"name"=>"Comment", "link"=>"http://www.facebook.com/149536368430/posts/10151515647758431"}, {"name"=>"Like", "link"=>"http://www.facebook.com/149536368430/posts/10151515647758431"}], "privacy"=>{"value"=>""}, "type"=>"photo", "status_type"=>"added_photos", "object_id"=>"10151515647728431", "created_time"=>"2013-04-08T18:03:01+0000", "updated_time"=>"2013-04-08T18:22:37+0000", "shares"=>{"count"=>1}, "likes"=>{"data"=>[{"name"=>"Penny Denton", "id"=>"100000188001574"}, {"name"=>"Angie Altman", "id"=>"100002250974930"}, {"name"=>"Jeannise R. Clagett", "id"=>"100002279556425"}, {"name"=>"Andy Tappan", "id"=>"100000485732671"}], "count"=>128}, "comments"=>{"data"=>[{"id"=>"149536368430_10151515647758431_9285816", "from"=>{"name"=>"Melissa Rivera", "id"=>"600150684"}, "message"=>"Thats cute!! Love the idea!! :)", "created_time"=>"April 08 at 06:22PM"}], "count"=>4}, "publishedDate"=>"2013-04-08 18:22:37", "source"=>"fb"} 

my_hash.reject { |key,value| key == 'comments' } 

这将返回一个没有注释的散列。

+0

感谢Ch Zeeshan提出这个问题。我几乎没有浪费大部分时间找到解决方案相同的情况;-) 并感谢Arjan工作... – 2014-12-18 07:21:31