I tried to implement the "Rendering JSON in actions" example from http://wiki.rubyonrails.com/rails/pages/HowtoGenerateJSON : @headers["Content-Type"] = "text/plain; charset=utf-8" data = { :foo => ''bar'', :etc => ''rez'' } render :text => data.to_json When I try to decode this in javascript with transport.responseText.evalJSON(true); I get this error: SyntaxError: Badly formed JSON string: ''{foo: "bar2", etc: "rez"}'' javascript seems to expect double quote around the key strings. does anyone know how I get this to work? thanks in advance!!! Björn --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 07 Aug 2007, at 20:49, dasboe wrote:> I tried to implement the "Rendering JSON in actions" example from > http://wiki.rubyonrails.com/rails/pages/HowtoGenerateJSON : > > @headers["Content-Type"] = "text/plain; charset=utf-8" > data = { :foo => ''bar'', :etc => ''rez'' } > render :text => data.to_json > > When I try to decode this in javascript with > > transport.responseText.evalJSON(true); > > I get this error: > > SyntaxError: Badly formed JSON string: ''{foo: "bar2", etc: "rez"}'' > > javascript seems to expect double quote around the key strings. does > anyone know how I get this to work?http://trac.codefront.net/jsonifier/ Best regards Peter De Berdt --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On 7 Aug., 22:14, Peter De Berdt <peter.de.be...-LPO8gxj9N8aZIoH1IeqzKA@public.gmane.org> wrote:> On 07 Aug 2007, at 20:49, dasboe wrote: > > > > > I tried to implement the "Rendering JSON in actions" example from > >http://wiki.rubyonrails.com/rails/pages/HowtoGenerateJSON: > > > @headers["Content-Type"] = "text/plain; charset=utf-8" > > data = { :foo => ''bar'', :etc => ''rez'' } > > render :text => data.to_json > > > When I try to decode this in javascript with > > > transport.responseText.evalJSON(true); > > > I get this error: > > > SyntaxError: Badly formed JSON string: ''{foo: "bar2", etc: "rez"}'' > > > javascript seems to expect double quote around the key strings. does > > anyone know how I get this to work? > > http://trac.codefront.net/jsonifier/ > > Best regards > > Peter De BerdtThank you very much! That''s what i was looking for. So I put ActiveSupport::JSON.unquote_hash_key_identifiers = false in environment.rb, restarted the WEBrick Server and everything worked just fine... Still - What I don''t understand is why Rails default behaviour is to produce invalid JSON!? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---