Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7ef21d80
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
7ef21d80
编写于
9月 14, 2012
作者:
F
Francesco Rodriguez
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
update AS/json docs [ci skip]
上级
5ea3f284
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
12 deletion
+20
-12
activesupport/lib/active_support/json/decoding.rb
activesupport/lib/active_support/json/decoding.rb
+4
-2
activesupport/lib/active_support/json/encoding.rb
activesupport/lib/active_support/json/encoding.rb
+16
-10
未找到文件。
activesupport/lib/active_support/json/decoding.rb
浏览文件 @
7ef21d80
...
...
@@ -39,8 +39,10 @@ def with_backend(name)
self
.
backend
=
old_backend
end
# Returns the class of the error that will be raised when there is an error in decoding JSON.
# Using this method means you won't directly depend on the ActiveSupport's JSON implementation, in case it changes in the future.
# Returns the class of the error that will be raised when there is an
# error in decoding JSON. Using this method means you won't directly
# depend on the ActiveSupport's JSON implementation, in case it changes
# in the future.
#
# begin
# obj = ActiveSupport::JSON.decode(some_string)
...
...
activesupport/lib/active_support/json/encoding.rb
浏览文件 @
7ef21d80
...
...
@@ -25,9 +25,10 @@ module JSON
# 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 objects 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'
})
# ActiveSupport::JSON.encode({
team: 'rails', players: '36'
})
# # => "{\"team\":\"rails\",\"players\":\"36\"}"
def
self
.
encode
(
value
,
options
=
nil
)
Encoding
::
Encoder
.
new
(
options
).
encode
(
value
)
...
...
@@ -51,7 +52,7 @@ def encode(value, use_options = true)
end
end
# like encode, but only calls as_json, without encoding to string
# like encode, but only calls as_json, without encoding to string
.
def
as_json
(
value
,
use_options
=
true
)
check_for_circular_references
(
value
)
do
use_options
?
value
.
as_json
(
options_for
(
value
))
:
value
.
as_json
...
...
@@ -60,7 +61,8 @@ def as_json(value, use_options = true)
def
options_for
(
value
)
if
value
.
is_a?
(
Array
)
||
value
.
is_a?
(
Hash
)
# hashes and arrays need to get encoder in the options, so that they can detect circular references
# hashes and arrays need to get encoder in the options, so that
# they can detect circular references.
options
.
merge
(
:encoder
=>
self
)
else
options
...
...
@@ -105,10 +107,12 @@ def check_for_circular_references(value)
'&'
=>
'\u0026'
}
class
<<
self
# If true, use ISO 8601 format for dates and times. Otherwise, fall back to the Active Support legacy format.
# If true, use ISO 8601 format for dates and times. Otherwise, fall back
# to the Active Support legacy format.
attr_accessor
:use_standard_json_time_format
# If false, serializes BigDecimal objects as numeric instead of wrapping them in a string
# If false, serializes BigDecimal objects as numeric instead of wrapping
# them in a string.
attr_accessor
:encode_big_decimal_as_string
attr_accessor
:escape_regex
...
...
@@ -231,11 +235,13 @@ class BigDecimal
# those libraries would get in general a wrong number and no way to recover
# other than manually inspecting the string with the JSON code itself.
#
# That's why a JSON string is returned. The JSON literal is not numeric, but if
# the other end knows by contract that the data is supposed to be a BigDecimal,
# it still has the chance to post-process the string and get the real value.
# That's why a JSON string is returned. The JSON literal is not numeric, but
# if the other end knows by contract that the data is supposed to be a
# BigDecimal, it still has the chance to post-process the string and get the
# real value.
#
# Use ActiveSupport.use_standard_json_big_decimal_format = true to override this behaviour
# Use <tt>ActiveSupport.use_standard_json_big_decimal_format = true</tt> to
# override this behaviour.
def
as_json
(
options
=
nil
)
#:nodoc:
if
finite?
ActiveSupport
.
encode_big_decimal_as_string
?
to_s
:
self
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录