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
I 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.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.