This project is archived and is in readonly mode.
encoding problem in json format response
-
rorra
I had the same problem with mysql and a utf-8 database
ruby-1.9.2-rc2 > p = Project.create(:name => 'áéíóú') => #<Project id: 2, name: "áéíóú", title: nil, description: nil, start_on: nil, end_on: nil, created_at: "2010-07-27 20:41:06", updated_at: "2010-07-27 20:41:06"> ruby-1.9.2-rc2 > p.to_json => "{\"project\":{\"created_at\":\"2010-07-27T20:41:06Z\",\"description\":null,\"end_on\":null,\"id\":2,\"name\":\"\\u00e1\\u00e9\\u00ed\\u00f3\\u00fa\",\"start_on\":null,\"title\":null,\"updated_at\":\"2010-07-27T20:41:06Z\"}}" ruby-1.9.2-rc2 > Project.first.to_json => "{\"project\":{\"created_at\":\"2010-07-27T20:41:06Z\",\"description\":null,\"end_on\":null,\"id\":2,\"name\":\"\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\\ufffd\",\"start_on\":null,\"title\":null,\"updated_at\":\"2010-07-27T20:41:06Z\"}}" ruby-1.9.2-rc2 > -
rorra
Now that I check better, my problem was not with the to_json method, but rather with mysql :P
Being p the record before being saved, and q the record after saving
ruby-1.9.2-rc2 > p.name => "á" ruby-1.9.2-rc2 > q.name => "\xC3\xA1" -
Kelvin Xiong
rorra, did you figure out a work around for this issue?
-
Sebastian A. Espindola
Everyone running on Ruby 1.9.x and using MySQL, should use the mysql2 gem.
It forces the use of UTF-8 and converts to/from UTF-8 automatically when needed. -
Alex MacCaw
- Tag changed from 3.0.0.rc, encoding, to_json to 3.0, 3.0.0.rc, encoding, to_json
Switching to the mysql2 gem doesn't completely solve the problem.
For example:
"".to_json.encoding #<Encoding:UTF-8> [].to_json.encoding #<Encoding:US-ASCII>
Attached is a patch which fixes the issue.
-
Margaret
Alex,
If I have older versions for ruby and for rails, I have to update both, install the mysql2 gem and update the database data?The path you are talking about ... i font understand :(
Tnk.
Margaret
-
rails
- Tag changed from 3.0, 3.0.0.rc, encoding, to_json to 30, 300rc, encoding, to_json
- State changed from new to open
This issue has been automatically marked as stale because it has not been commented on for at least three months.
The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.
Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.
-
rails
- State changed from open to stale
-
kalyan
I had the same problem with rendering response as json. I'm uploading images to the database, while rendering it as json
Eg: render :json => material.to_json
I'm getting following error
ArgumentError in ApiController#download_object
redundant UTF-8 sequence
But the same thing is working fine with to_xml. Please any one let me know what is the issue here.
Thanks..