I have a Flash application that is sending JSON data to a Rails app. I want to be able to read the JSON from the controller. Does anyone know where I can go to figure this out? I''ve Google''d around but can only find instances of converting to JSON, not the other way. Example: Flash -> Sends JSON -> Rails Controller receives JSON and converts it to a class -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Haliday wrote:> Flash -> Sends JSON -> Rails Controller receives JSON and converts it to > a classThis is what I''ve come up with so far in my controller: incoming_data = request.env[''RAW_POST_DATA''] my_json_stuff = incoming_data.to_json I''m guessing there is a better way? Also, how do I access the JSON data? Ive tried: my_json_stuff[''myValue''] and my_json_stuff.myValue etc. Nothing seems to work. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Mark Haliday wrote:> This is what I''ve come up with so far in my controller: > > incoming_data = request.env[''RAW_POST_DATA''] > my_json_stuff = incoming_data.to_jsonI think you''ve got this the wrong way round? Flash should be sending the data as string encoded using JSON, you want to make it back into a ruby structure. Using "to_json" on a hash, will make it into a JSON string, you want to use "JSON.parse">> require ''json''=> []>> hash = {:a => {:b => :c}}=> {:a=>{:b=>:c}}>> json_1 = hash.to_json=> "{\"a\":{\"b\":\"c\"}}">> json_2 = JSON.unparse(hash)=> "{\"a\":{\"b\":\"c\"}}">> JSON.parse(json_1)=> {"a"=>{"b"=>"c"}} Saying that, I don''t know how Flash would be sending you the data. I guess you need to do some debugging on params and RAW_POST_DATA until you find your JSON. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---