开发者

Unicode characters break JSON encode/decode

开发者 https://www.devze.com 2023-03-10 17:16 出处:网络
I\'m trying to save something as JSON, but it breaks after a Unicode character: Obj: { comment => \"test test test £466\"

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

精彩评论

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

关注公众号