Module: WebStub::JSON

Defined in:
lib/webstub/json.rb

Class Method Summary collapse

Class Method Details

.generate(hash) ⇒ Object


3
4
5
6
7
8
# File 'lib/webstub/json.rb', line 3

def self.generate(hash)
  error = Pointer.new(:object)
  result = NSJSONSerialization.dataWithJSONObject(hash, options:0, error:error)

  NSString.alloc.initWithData(result, encoding:NSUTF8StringEncoding)
end

.parse(str) ⇒ Object


10
11
12
13
14
15
16
17
18
19
20
# File 'lib/webstub/json.rb', line 10

def self.parse(str)
  data = str
  unless data.is_a?(NSData)
    data = str.dataUsingEncoding(NSUTF8StringEncoding)
  end

  error = Pointer.new(:object)
  result = NSJSONSerialization.JSONObjectWithData(data, options: 0, error: error)

  result
end