Hashie :: Mash从字符串恢复

时间:2012-07-30 17:00:03

标签: ruby hash

我在这个问题上非常挣扎。我已将Hashie::Mash存储到字符串中,我很难将其恢复为哈希值。

这是字符串:

"--- !map:Hashie::Mash \ncreated_at: Mon Jul 30 15:42:20 +0000 2012\nid: 229965155759439872\nid_str: \"229965155759439872\"\ntext: \"#streetart encore plus impressionnant de plus pr\\xC3\\xA8s http://t.co/lUUmXFYs\"\nsource: <a href=\"http://twicca.r246.jp/\" rel=\"nofollow\">twicca</a>\ntruncated: false\nin_reply_to_status_id: \nin_reply_to_status_id_str: \nin_reply_to_user_id: \nin_reply_to_user_id_str: \nin_reply_to_screen_name: \nuser: !map:Hashie::Mash \n id: 15762429\n id_str: \"15762429\"\n name: Cyroul\n screen_name: Cyroultwit\n location: Paris\n description: alias Cyril Rimbaud, explorateur de TAZ, creative Technologist, fondateur du laboratoire Curiouser, enseignant au CELSA et casseur de mythes publicitaires.\n url: http://www.cyroul.com\n protected: false\n followers_count: 7431\n friends_count: 1065\n listed_count: 481\n created_at: Thu Aug 07 12:05:21 +0000 2008\n favourites_count: 10\n utc_offset: 3600\n time_zone: Paris\n geo_enabled: false\n verified: false\n statuses_count: 12726\n lang: fr\n contributors_enabled: false\n is_translator: false\n profile_background_color: 1A1B1F\n profile_background_image_url: http://a0.twimg.com/profile_background_images/6800607/main-cyr.jpg\n profile_background_image_url_https: https://si0.twimg.com/profile_background_images/6800607/main-cyr.jpg\n profile_background_tile: false\n profile_image_url: http://a0.twimg.com/profile_images/2018752881/tete-etoiles-petit-128_normal.jpg\n profile_image_url_https: https://si0.twimg.com/profile_images/2018752881/tete-etoiles-petit-128_normal.jpg\n profile_link_color: 2FC2EF\n profile_sidebar_border_color: 181A1E\n profile_sidebar_fill_color: \"252429\"\n profile_text_color: \"666666\"\n profile_use_background_image: true\n show_all_inline_media: true\n default_profile: false\n default_profile_image: false\n following: false\n follow_request_sent: false\n notifications: false\ngeo: \ncoordinates: \nplace: \ncontributors: \nretweet_count: 0\nentities: !map:Hashie::Mash \n hashtags: \n - !map:Hashie::Mash \n text: streetart\n indices: \n - 0\n - 10\n urls: \n - !map:Hashie::Mash \n url: http://t.co/lUUmXFYs\n expanded_url: http://yfrog.com/nw86guqj\n display_url: yfrog.com/nw86guqj\n indices: \n - 51\n - 71\n user_mentions: []\n\nfavorited: false\nretweeted: false\npossibly_sensitive: false\n"

我怎样才能获得哈希值?非常感谢提前!

1 个答案:

答案 0 :(得分:2)

使用YAML看起来像serialized字符串。您可以像这样反序列化:

require "yaml"
require "hashie"

YAML.load(your_string)