typealias JSON = AnyObject
typealias JSONDictionary = Dictionary<String, AnyObject>
typealias JSONArray = Array<AnyObject>
func _JSONString(object: JSON)->String? {
return object as? String
}
func _JSONInt(object: JSON)->Int? {
return object as? Int
}
func _JSONObject(object: JSON)->JSONDictionary {
return object as? JSONDictionary
}
func decodeJSON(data: NSData)->Result<JSON> {
let jsonOptional: JSON! = try?NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(rawValue:0))
return resultFromOptional(jsonOptional, error: NSError())
}
func decodeObject<U: JSONDecodable>(json: JSON)->Result<U> {
return resultFromOptional(U.decode(json), error:NSError())
}
网友评论