//declaration
//string
var toLocation:String = ""
//array
var viaStationPlace_Array : NSArray = []
func webService() {
let url = NSURL(string: "http://url")
let request = NSURLRequest(URL: url!)
let config = NSURLSessionConfiguration.defaultSessionConfiguration()
let session = NSURLSession(configuration: config)
let task = session.dataTaskWithRequest(request, completionHandler: {(data, response, error) in
// notice that I can omit the types of data, response and error
do{
if let jsonResult = try NSJSONSerialization.JSONObjectWithData(data!, options: NSJSONReadingOptions.MutableContainers) as? NSDictionary {
//from place
let fromLocation_Array = jsonResult.objectForKey("data")!.valueForKey("loc")
self.fromLocation = fromLocation_Array! .objectAtIndex(0) as! String
}
}
catch{
print("Somthing wrong")
}
self.callWebService()
});
// do whatever you need with the task e.g. run
task.resume()
}
Sign up here with your email
ConversionConversion EmoticonEmoticon