class MultiJson::Adapters::Nsjsonserialization - multi_json-1.10.1 Documentation

# class MultiJson::Adapters::Nsjsonserialization

### Constants

ParseError

### Public Instance Methods

dump(object, options={}) click to toggle source
Calls superclass method MultiJson::Adapters::OkJson#dump

    # File lib/multi_json/adapters/nsjsonserialization.rb, line 21
    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={}) click to toggle source
Calls superclass method MultiJson::Adapters::OkJson#load

    # File lib/multi_json/adapters/nsjsonserialization.rb, line 9
    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