【问题标题】:Unicode characters break JSON encode/decodeUnicode 字符破坏 JSON 编码/解码
【发布时间】:2011-06-05 01:49:55
【问题描述】:

我正在尝试将某些内容另存为 JSON,但它在 Unicode 字符后中断:

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

=> to_json 结果

{
    "comment":"test test test "
}

Obj.inspect 放:

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

这里有什么提示吗?

【问题讨论】:

  • 没关系,我用 Iconv.conv('utf-8', 'ISO-8859-1', "incoming text") 转换了传入的字符串
  • 然后添加一个答案什么是解决方案并接受它。这样,您的问题就不会悬而未决。 ;)

标签: ruby json


【解决方案1】:

听起来Daniel有一个使用Iconv的解决方案,即:

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

还有其他方法可以解决这个问题吗?在another question 我读到有人在heroku 上遇到了iconv 问题

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-26
    • 2013-08-06
    • 1970-01-01
    • 2017-01-17
    • 2019-12-10
    • 2018-12-11
    相关资源
    最近更新 更多