"Some String \xAE".to_json gives an illegal/malformed error?

Discussion in 'Ruby' started by Blackie, Oct 24, 2007.

  1. Blackie

    Blackie Guest

    Call me crazy, but I must be missing some fundamental understanding
    here.
    json.rubyforge.org/) this should be working but I'm getting a
    JSON::GeneratorError. Any insight you may have is appreciated.

    Given this:

    require 'json'
    => true

    s = ["MyStuff \xAE"]
    => ["MyStuff \256"]

    s.to_json
    JSON::GeneratorError: source sequence is illegal/malformed
    from (irb):16:in `to_json'
    from (irb):16

    Since that string has a unicode char in it, should it not be escape to
    \uXXXX when re convert to JSON?

    Any help is appreciated.
     
    Blackie, Oct 24, 2007
    #1
    1. Advertisements

  2. Blackie

    Blackie Guest

    Never mind. Encoding on the DB is defaulting to latin-1. What I
    thought was unicode strings weren't. *Sigh* :)


     
    Blackie, Oct 25, 2007
    #2
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.