您可以这样做:
var url : String = "http://google.com?test=toto&test2=titi"var request : NSMutableURLRequest = NSMutableURLRequest()request.URL = NSURL(string: url)request.HTTPMethod = "GET"NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil let jsonResult: NSDictionary! = NSJSONSerialization.JSonObjectWithData(data, options:NSJSONReadingOptions.MutableContainers, error: error) as? NSDictionary if (jsonResult != nil) { // process jsonResult } else { // couldn't load JSON, look at error }})
编辑:对于对此有疑问的人,也许您的JSON流是数组[]而不是对象{},因此您必须将jsonResult更改为
NSArray而不是NSDictionary
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)