Module: MultiJson::Adapters::Nsjsonserialization

Extended by:
Nsjsonserialization, OkJson
Included in:
Nsjsonserialization
Defined in:
lib/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb

Constant Summary collapse

ParseError =
::MultiJson::OkJson::Error

Instance Method Summary collapse

Methods included from OkJson

prepare_object, stringify_keys, symbolize_keys

Instance Method Details

#dump(object, options = {}) ⇒ Object


22
23
24
25
26
27
28
29
30
31
# File 'lib/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb', line 22

def dump(object, options={})
  pretty = options[: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, options)
  end
end

#load(string, options = {}) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/vendor/multi_json/lib/multi_json/adapters/nsjsonserialization.rb', line 10

def load(string, options={})
  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 options[:symbolize_keys]
    object
  else
    super(string, options={})
  end
end