Hashie::Mash restore from string

一笑奈何 提交于 2021-01-28 02:04:53

问题


I'm quite struggling on this issue. I've stored a Hashie::Mash into a string, and I'm having a hard time restoring it back as a hash.

Here's the string:

"--- !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"

How can i get the hash back? Thanks a lot in advance!


回答1:


Looks like you serialized the String using YAML. You can deserialize it like this:

require "yaml"
require "hashie"

YAML.load(your_string)


来源:https://stackoverflow.com/questions/11726137/hashiemash-restore-from-string

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!