Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

data returned as String instead of Hash #48

Open
yosefsun opened this issue May 13, 2015 · 1 comment
Open

data returned as String instead of Hash #48

yosefsun opened this issue May 13, 2015 · 1 comment

Comments

@yosefsun
Copy link

when an event binding is triggered, "data" variable is returned as a String. I actually had to manipulate it in order to cast it into a Hash type :

data.gsub!('":"','"=>"')
data = eval(data)

makes sense to have the gem cast it into a Hash...

@AvaelKross
Copy link

assuming that many devs are using websockets for chats and other stuff with user's input, it's a bad idea to use eval.

instead, i was able to get json using these commands:

data.gsub!('\"', '"').gsub!('\\\\','\\') # second gsub may be omitted; but without it, unicode chars(non-latin) wont be converted properly
clean_data = JSON.parse(data[1..-2]) # [1..-2] to remove first and last `"` symbol

hope this help someone :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants