[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

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

Blackie

10/24/2007 10:11:00 PM

Call me crazy, but I must be missing some fundamental understanding
here.

>From what I can read on the JSON gem located here (http://
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.

1 Answer

Blackie

10/24/2007 11:03:00 PM

0

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


On Oct 24, 6:11 pm, Blackie <mudsweatande...@gmail.com> wrote:
> Call me crazy, but I must be missing some fundamental understanding
> here.
>
> >From what I can read on the JSON gem located here (http://
>
> 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.