Topic: Converting this string to Hash - {"connectState":1,...}

Hey Guys,

Looking for the fastest, and most refactored way to convert this string

{"connectState":1,"oneLineStorySetting":1,"shortStorySetting":1,"fullStorySetting":1}

into a Hash. This might look familiar to some of you, if not, it is a cookie that Facebook passes to Facebook Connect Apps. Brewing up a test app, and hopefully a future plugin for Rails and Facebook Connect.

Thanks in advance! (I never was good with regex ;P)

Re: Converting this string to Hash - {"connectState":1,...}

looks like JSON format to me... have a look at the JSON gem

http://json.rubyforge.org

Re: Converting this string to Hash - {"connectState":1,...}

Looks like JSON format to me:
sudo gem install json.

items = JSON.parse(%Q{{"connectState":1,"oneLineStorySetting":1,"shortStorySetting":1,"fullStorySetting":1}})

This will give you a ruby hash like so:
{"connectState"=>1, "oneLineStorySetting"=>1, "fullStorySetting"=>1, "shortStorySetting"=>1}

EDIT: Duplex beat me to it hehe! big_smile

Last edited by RailsRocks (2008-12-27 15:21:20)

http://www.webyfi.com
It's not the size of the app that matters, it's how you code it. ~ railsenvy

Re: Converting this string to Hash - {"connectState":1,...}

Thanks a lot guys... JSON aye?? That's nice to know... Now I will need to learn JSON! ;P