Is there a method to convert a string representing a hash to a hash? Ex: var string="{name: ''Yogi Bear'', position: ''pic-a-nic basket collector''}"; //This string is passed from outside of the javascript code, shown here as a declaration for simplicity //convert it to hash with something like: var h = $H(string); //which i know won''t work Ive found if i convert the string to: "name=Yogi Bear&position=pic-a- nic basket collector" and then use the toQueryParams() method on it, i can then pass this onto my ajax handler. However, for other reasons, I would like to be able to have the string stored as a string representing a hash and then have my javascript code convert that string to an actual hash. Is there a way to accomplish this? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey there, sliver a écrit :> var string="{name: ''Yogi Bear'', position: ''pic-a-nic basket > collector''}";If you just go the extra mile and put quotes around the key names, making it a valid JSON serialized form, you''ll be able to leverage the new JSON features (including, of course, parseJSON) Tobie recently provided as a branch changeset [1]. They''re likely to become available in the next point release. Until then, you can get Tobie''s patch file and apply it over your copy of Prototype... [1] http://dev.rubyonrails.org/changeset/6210 -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks for the info Christophe! Unfortunately, I dont like to patch source code in order to avoid creating other bugs. However, you gave me an idea and I looked at the source to see if they were simply using an eval (which I loathe to do usually), but, that is what they appeared to use to convert JSON into a hash object. So, I went with my original idea which is to simply do this: var string = "{''name'': ''Yogi Bear'', ''position'': ''pic-a-nic basket collector''}"; var hashObj = $H(eval(''('' + string + '')'')); This works, I just was hoping to avoid using an eval. Thanks again for your help! Cheers! On Feb 24, 11:03 am, Christophe Porteneuve <t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org> wrote:> Hey there, > > sliver a écrit : > > > var string="{name: ''Yogi Bear'', position: ''pic-a-nic basket > > collector''}"; > > If you just go the extra mile and put quotes around the key names, > making it a valid JSON serialized form, you''ll be able to leverage the > new JSON features (including, of course, parseJSON) Tobie recently > provided as a branch changeset [1]. They''re likely to become available > in the next point release. Until then, you can get Tobie''s patch file > and apply it over your copy of Prototype... > > [1]http://dev.rubyonrails.org/changeset/6210 > > -- > Christophe Porteneuve a.k.a. TDD > "[They] did not know it was impossible, so they did it." --Mark Twain > Email: t...-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---