Class: MultiJson::Adapters::Nsjsonserialization
- Inherits:
-
OkJson
- Object
- MultiJson::Adapter
- OkJson
- MultiJson::Adapters::Nsjsonserialization
- Defined in:
- lib/multi_json/adapters/nsjsonserialization.rb
Constant Summary collapse
Instance Attribute Summary
Attributes included from Options
Instance Method Summary collapse
Methods inherited from MultiJson::Adapter
activate!, defaults, dump, load
Methods included from Options
#default_dump_options, #default_load_options
Instance Method Details
#dump(object, options = {}) ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/multi_json/adapters/nsjsonserialization.rb', line 21 def dump(object, ={}) pretty = [:pretty] ? NSJSONWritingPrettyPrinted : 0 object = object.as_json if object.respond_to?(:as_json) if NSJSONSerialization.isValidJSONObject(object) data = NSJSONSerialization.dataWithJSONObject(object, options: pretty, error: nil) NSMutableString.alloc.initWithData(data, encoding: NSUTF8StringEncoding) else super(object, ) end end |
#load(string, options = {}) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/multi_json/adapters/nsjsonserialization.rb', line 9 def load(string, ={}) string = string.read if string.respond_to?(:read) data = string.dataUsingEncoding(NSUTF8StringEncoding) object = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves, error: nil) if object object = symbolize_keys(object) if [:symbolize_keys] object else super(string, ={}) end end |