aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/json
diff options
context:
space:
mode:
authorVijay Dev <vijaydev.cse@gmail.com>2012-05-30 22:53:52 +0530
committerVijay Dev <vijaydev.cse@gmail.com>2012-05-30 22:53:52 +0530
commitec74763c393c6a5f54eb64f0313610aead7f815a (patch)
tree39e3712c4cfc589083ed5072b6b8373361334441 /activesupport/lib/active_support/json
parent0406a13fac7f809cb511e45583259e66d8739b4f (diff)
parent032f502f1221129d8446d3e25cd8956469b43456 (diff)
downloadrails-ec74763c393c6a5f54eb64f0313610aead7f815a.tar.gz
rails-ec74763c393c6a5f54eb64f0313610aead7f815a.tar.bz2
rails-ec74763c393c6a5f54eb64f0313610aead7f815a.zip
Merge branch 'master' of github.com:lifo/docrails
Diffstat (limited to 'activesupport/lib/active_support/json')
-rw-r--r--activesupport/lib/active_support/json/decoding.rb5
-rw-r--r--activesupport/lib/active_support/json/encoding.rb5
2 files changed, 9 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/json/decoding.rb b/activesupport/lib/active_support/json/decoding.rb
index 986a764479..72fd97ceee 100644
--- a/activesupport/lib/active_support/json/decoding.rb
+++ b/activesupport/lib/active_support/json/decoding.rb
@@ -8,6 +8,11 @@ module ActiveSupport
module JSON
class << self
+ # Parses a JSON string (JavaScript Object Notation) into a hash.
+ # See www.json.org for more info.
+ #
+ # ActiveSupport::JSON.decode("{\"team\":\"rails\",\"players\":\"36\"}")
+ # => {"team" => "rails", "players" => "36"}
def decode(json, options ={})
data = MultiJson.load(json, options)
if ActiveSupport.parse_json_times
diff --git a/activesupport/lib/active_support/json/encoding.rb b/activesupport/lib/active_support/json/encoding.rb
index 41fe61e790..ded02c873a 100644
--- a/activesupport/lib/active_support/json/encoding.rb
+++ b/activesupport/lib/active_support/json/encoding.rb
@@ -25,7 +25,10 @@ module ActiveSupport
# matches YAML-formatted dates
DATE_REGEX = /^(?:\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})?))$/
- # Dumps object in JSON (JavaScript Object Notation). See www.json.org for more info.
+ # Dumps objects in JSON (JavaScript Object Notation). See www.json.org for more info.
+ #
+ # ActiveSupport::JSON.encode({team: 'rails', players: '36'})
+ # # => "{\"team\":\"rails\",\"players\":\"36\"}"
def self.encode(value, options = nil)
Encoding::Encoder.new(options).encode(value)
end