It becomes much easier when you work with a valid json string (i.e.
all keys are quoted) and String#isJSON returns true:
var s = ''{"foo": "bar"}'';
s.isJSON(); // => true
var hash = $H(s.evalJSON());
hash.keys(); // => ''foo''
hash.values(); // => ''bar''
hash.inspect(); // => "#<Hash:{''foo'':
''bar''}>"
Best,
kangax
On Feb 25, 12:56 pm, supremebo
<kasperv...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> how do i turn a string into a hash? why does this not work???
>
> var test = "{ test: ''dfgj''}";
> console.log($H(test).inspect())
>
> half the prototype source code get inside the hash it makes???
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Spinoffs" group.
To post to this group, send email to
rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-spinoffs?hl=en
-~----------~----~----~----~------~----~------~--~---