ActiveSupport::JSON
decode(json)
Converts a JSON string into a Ruby object.
[ hide source ]
# File vendor/rails/activesupport/lib/active_support/json/decoding.rb, line 11
11: def decode(json)
12: YAML.load(convert_json_to_yaml(json))
13: rescue ArgumentError => e
14: raise ParseError, "Invalid JSON string"
15: end
encode(value, options = {})
Converts a Ruby object into a JSON string.
[ hide source ]
# File vendor/rails/activesupport/lib/active_support/json/encoding.rb, line 19
19: def encode(value, options = {})
20: raise_on_circular_reference(value) do
21: value.send(:to_json, options)
22: end
23: end
Ruby处理xml、json等数据格式
最新推荐文章于 2019-08-15 09:38:32 发布
本文介绍了Rails框架中ActiveSupport库的JSON编解码方法。详细解释了如何将JSON字符串转换为Ruby对象及反之的方法,包括异常处理过程。
403

被折叠的 条评论
为什么被折叠?



