Created
April 6, 2015 22:34
-
-
Save zkkmin/d8caf49b61ab6c6421ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit | |
import XCPlayground | |
XCPSetExecutionShouldContinueIndefinitely(continueIndefinitely: true) | |
let session = NSURLSession(configuration: NSURLSessionConfiguration.defaultSessionConfiguration()) | |
let urlString = "http://www.onemap.sg/API/services.svc/basicSearch?token=qo/s2TnSUmfLz+32CvLC4RMVkzEFYjxqyti1KhByvEacEdMWBpCuSSQ+IFRT84QjGPBCuz/cBom8PfSm3GjEsGc8PkdEEOEr&wc=SEARCHVAL%20LIKE%20%27CITY$%27&otptFlds=CATEGORY&returnGeom=0&nohaxr=10" | |
session.dataTaskWithURL(NSURL(string: urlString)!, completionHandler: { | |
(taskData, taskResponse, taskError) -> Void in | |
var jsonReadError: NSError? | |
var jsonResult = NSJSONSerialization.JSONObjectWithData(taskData, options: NSJSONReadingOptions.MutableContainers, error: &jsonReadError) as NSDictionary | |
//var jsonResult = NSJSONSerialization.JSONObjectWithData(taskData, options: NSJSONReadingOptions.MutableContainers, error: &err) as NSArray | |
//println("\(jsonResult)") | |
for (key, value) in jsonResult{ | |
println("\(key) : \(value)") | |
} | |
let arr = jsonResult["SearchResults"] as NSArray | |
//{ | |
// CATEGORY = Building; | |
// SEARCHVAL = "CITY BACKPACKERS"; | |
// X = "29554.0005"; | |
// Y = "30024.3460"; | |
// } | |
println("\(arr[0])") | |
println("\(arr[1])") | |
let categ = arr[1]["CATEGORY"] | |
let categ1 = arr[1]["SEARCHVAL"] | |
let categ2 = arr[1]["X"] | |
let categ3 = arr[1]["Y"] | |
println("\(arr[2])") | |
println("\(jsonReadError)") | |
println("\(taskData)") | |
println("\(taskResponse)") | |
}).resume() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment