开发者

Unicode characters break JSON encode/decode

I'm trying to save something as JSON, but it breaks after a Unicode character:

Obj: {
    comment => "test test test £466"
}

=> to_json results in

{
    "comment":"test tes开发者_StackOverflow社区t test "
}

Obj.inspect puts:

`comment => "test test test \243466"`

Any hints here?


It sounds like Daniel has a solution using Iconv, namely:

Iconv.conv('utf-8', 'ISO-8859-1', "incoming text") 

Is there another way to to this though? In another question I read that someone was having trouble with iconv on heroku

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜