方法
- D
- E
- L
- P
常數
DATETIME_REGEX | = | /\A(?:\d{4}-\d{2}-\d{2}|\d{4}-\d{1,2}-\d{1,2}[T \t]+\d{1,2}:\d{2}:\d{2}(\.[0-9]*)?(([ \t]*)Z|[-+]\d{2}?(:\d{2})?)?)\z/ |
DATE_REGEX | = | /\A\d{4}-\d{2}-\d{2}\z/ |
符合 YAML 格式的日期 |
類別公開方法
decode(json) 連結
將 JSON
字串(JavaScript Object
符號)解析成雜湊。有關更多資訊,請參閱 www.json.org。
ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
=> {"team" => "rails", "players" => "36"}
別名為:load
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/json/decoding.rb, line 22 def decode(json) data = ::JSON.parse(json, quirks_mode: true) if ActiveSupport.parse_json_times convert_dates_from(data) else data end end
encode(value, options = nil) 連結
別名為:dump
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/json/encoding.rb, line 22 def encode(value, options = nil) Encoding.json_encoder.new(options).encode(value) end
parse_error() 連結
傳回在解碼 JSON
時發生錯誤時所引發的錯誤類別。使用此方法表示您不會直接依賴 ActiveSupport 的 JSON
實作,以防它在未來有所變更。
begin
obj = ActiveSupport::JSON.decode(some_string)
rescue ActiveSupport::JSON.parse_error
Rails.logger.warn("Attempted to decode invalid JSON: #{some_string}")
end
來源:顯示 | 在 GitHub 上
# File activesupport/lib/active_support/json/decoding.rb, line 43 def parse_error ::JSON::ParserError end