【问题标题】:rails incompatible character encodings: UTF-8 and ASCII-8BIT in jsonrails 不兼容的字符编码:json 中的 UTF-8 和 ASCII-8BIT
【发布时间】:2014-09-29 01:41:33
【问题描述】:

我使用 RestClient 通过 GET 从 Web 服务中检索 json 字符串。 这工作正常,但只要字符串中有元音变音(ü)和其他字符(例如ß),我就会在我的视图中收到此错误

@output = RestClient.get 'https://myurl.com/api/v1/orders/53e0ae7f6630361c46060000', {:authorization => 'Token xxxxxx', :content_type => :json, :accept => :json}

<%= @output %>

=>

Encoding::CompatibilityError
incompatible character encodings: UTF-8 and ASCII-8BIT

知道如何解决这个问题吗?

【问题讨论】:

    标签: ruby-on-rails json utf-8 character-encoding


    【解决方案1】:

    添加此行后解决

    @output = @output.force_encoding('utf-8').encode
    

    【讨论】:

      猜你喜欢
      • 2011-05-26
      • 2011-12-14
      • 1970-01-01
      • 2011-07-14
      • 1970-01-01
      • 1970-01-01
      • 2012-07-12
      • 2011-10-17
      • 2016-04-27
      相关资源
      最近更新 更多