On Aug 10, 10:02 pm, Calvin Nguyen <[email protected]>
wrote:
> Question:
> Hi, our company is using Ruby 1.8.6 with Rails 2.2.2.  Does anyone
> know how we can explicitly specify what encoding to use when calling
> .to_json on an ActiveRecord?
>
> Description:
> We have some multibyte characters in our database.  For example we
> have a table with a name column that has this French accented e: Café
> Records.  When we serialize this object using ActiveRecord's to_xml()
> everything looks fine in the browser and with our json objects.
>
> When we render JSON using to_json() we are seeing problems where the
> accented 'e' character is getting mangled and causes our calling web
> client to fail since it's expecting properly UTF-8 encoded characters.
>

What's actually stored in the database ? If you open up a console and
find the relevant object in the database what does the name attribute
contain ? I don't think that to_json does much more than spit out the
data ActiveRecord already has.

Fred
> If we use the browser to submit HTTP Get requesting JSON format, save
> the file and view it in binary mode in Hexadecimal representation,
> this is what we get.  It looks like this is using extended ASCII.
>
> Bytes                          Text
> 43 61 66 E9                    C a f (should be accented e but get weird
> block unprintable character)
>
> If we save that same file from above and convert it to UTF-8,  we get an
> extra byte that seems to be proper UTF-8 encoding as shown below.
>
> Bytes                          Text
> 43 61 66 C3 A9                 C a f é (correctl get accented e)
>
> Can someone tell me how they've made to_json() UTF-8 compliant?
> Thanks in advance, Calvin.
> --
> Posted viahttp://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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to