Class: MultiJson::Adapters::Nsjsonserialization

### Home Classes Methods

### In Files

- lib/multi_json/adapters/nsjsonserialization.rb

### Parent

MultiJson::Adapters::OkJson

### Methods

- #dump
- #load

### Class/Module Index

Quicksearch

- MultiJson
- MultiJson::Adapter
- MultiJson::Adapters
- MultiJson::Adapters::Gson
- MultiJson::Adapters::Jrjackson
- MultiJson::Adapters::JsonCommon
- MultiJson::Adapters::JsonGem
- MultiJson::Adapters::JsonPure
- MultiJson::Adapters::Nsjsonserialization
- MultiJson::Adapters::Oj
- MultiJson::Adapters::OkJson
- MultiJson::Adapters::Yajl
- MultiJson::ConvertibleHashKeys
- MultiJson::LoadError
- MultiJson::OkJson
- MultiJson::OkJson::Error
- MultiJson::OkJson::Utf8Error
- MultiJson::Options

No matching classes.

# MultiJson::Adapters::Nsjsonserialization

### Constants

ParseError

### Public Instance Methods

dump(object, options={}) click to toggle source

    # 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

    # 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

[Validate]

Generated with the Darkfish Rdoc Generator 2.