2013-04-10 111 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