【问题标题】:[DEPRECATION] MultiJson.decode is deprecated[弃用] MultiJson.decode 已弃用
【发布时间】:2012-04-17 11:30:04
【问题描述】:

我有一个简单的类,我想在用户请求服务器时将其输出为 JSON。

class GeoName

include ActiveModel::Validations
include ActiveModel::Serialization

validates :country_name, :presence => true, :length => {:minimum => 1}
validates :country_code, :presence => true, :length => {:minimum => 1}
validates :province, :presence => true, :length => {:minimum => 1}
validates :district, :presence => true, :length => {:minimum => 1}
validates :zip_code, :presence => true, :length => {:minimum => 1}
validates :city, :presence => true, :length => {:minimum => 1}
validates :street, :presence => true, :length => {:minimum => 1}

attr_accessor :country_name, :country_code, :province, :district, :zip_code, :city, :street


def attributes
 @attributes ||= {'country_name' => country_name, 'country_code' => country_code, 'province' => province,'district' => district,'zip_code' => zip_code,'city' => city, 'street' => street}
end


end

在控制器中我执行以下操作:

def index
    geoname = GeoName.new 
    geoname.street = "blablabla"
    geoname.city = "blablabla" 
    render :json => geoname.to_json
  end

在 routes.rb 中

controller :testcontroller do
    match 'testme', :to => :index
  end

当我请求 url localhost:3000/testme 时,我收到一个有效的 JSON 响应。但是控制台中存在弃用警告

rvm/gems/ruby-1.9.3-p125@geo/gems/activesupport-3.1.0/lib/active_support/json/decoding.rb:12:in `decode': [DEPRECATION] MultiJson.decode is deprecated and will be removed in the next major version. Use MultiJson.load instead.

Ruby 版本 1.9.3-p125 和 rails - 3.1.0。

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3.1


    【解决方案1】:

    快速谷歌会显示这是来自MultiJSON 的警告,应该在进一步的版本中消失(当已弃用的代码及其消息从 gem 代码中删除时)。基本上这是对在代码中使用MultiJSON.decode 的开发人员的警告。如果您的代码中没有使用MultiJSON.decode,请忽略它。

    一旦依赖的 gem 被更新并且您将更新的 gem 捆绑到您的项目中,该消息可能会消失。

    【讨论】:

      猜你喜欢
      • 2014-02-12
      • 1970-01-01
      • 2016-03-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-02-16
      • 2020-04-20
      • 1970-01-01
      相关资源
      最近更新 更多