module WebStub::JSON

Public Class Methods

generate(hash) click to toggle source
# 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) click to toggle source
# 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