JSON data not decoded in Rails

Hello all,

I'm trying to send some json data from the browser to the server using
prototype without success. On the server side ActiveSupport::JSON.decode
isn't decoding the data.

What happens ? render :text => my_json might produce some odd output
since you're just calling to_s on a hash which doesn't do anything
very interesting. render :text => my_json.inspect() would produce more
readable output


Hello Fred,

Thanks for the answer but the problem remains.

The "render :text => my_json" part is just a debug line I added.
I'm interested in manipulating the json data before sending an answer to
the browser.
I've done what you said but my_json.inspect() returns the same output.

From what I gathered the my_json is returned as a String object instead
of an Hash.

(rdb:5) my_json = ActiveSupport::JSON.decode(params["_json"])
(rdb:5) my_json.class

If I use the same json string directly in the controller in Rails the
decode works so it must have something to do with the way I'm creating
the Ajax request, but I still don't know what I'm doing wrong.

(rdb:5) my_json2 = ActiveSupport::JSON.decode("{name: 'Violet',
occupation: 'character', age: 25 }")
{"occupation"=>"character", "name"=>"Violet", "age"=>25}
(rdb:5) my_json2.class

Best regards,

Frederick Cheung wrote: