Serialization and deserialization of JSON with special characters with RAILS

I really feel a little stupid about what to do to make this simple work, I looked around, and not a single answer seemed to really answer this, can someone tell me how to serialize and deserialize something simple:

JSON.parse("É".to_json)
JSON::ParserError: 757: unexpected token at '"\u00e9"'

EDIT:

The real problem was more akin to storing the hash in the database using é in a string, for example:

{"Hu00c9MO":"JOUR"}

It seems that the string is not very good and I cannot return é after decoding from JSON

+4
source share
2 answers

I think the problem is not in "É". I just tried this:

JSON.parse("A".to_json)
JSON::ParserError: 757: unexpected token at '"A"'

, , .

, "É" JSON, to_json , , . , :

JSON.parse({'key' => 'É'}.to_json)

docs:

JSON.generate JSON . to_json, , Ruby,

(.to_json JSON.generate)

+4

Accord http://www.json.org/ JSON {id: value} [value1, value2].

. - : JSON.parse(["É"].to_json) JSON.parse({value: "É"}.to_json)

. :

Accord http://www.json.org JSON {id: value}, UNICODE charecter "\ charecter. " É" id.

, "\" , "\" "\" .

+2

All Articles