First, let me recommend the best 3rd party API for REST calls (HTTP) which called Alamofire.
If you use the below Alamofire example:
Alamofire.request(.GET, "https://httpbin.org/get", parameters: ["foo": "bar"])
.responseJSON { response in
print(response.request) // original URL request
print(response.response) // URL response
print(response.data) // server data
print(response.result) // result of response serialization
// Parsing the JSON
if let JSON = response.result.value {
print("JSON: \(JSON)")
// The actual cast to Dictionary
let jsonDictionary = JSON as! Dictionary<String, AnyObject>
}
}
Basically jsonDictionary
will be your JSON dictionary that the keys are String
and the values are of type AnyObject
(so you could cast to what ever you need) and now you can do the below calls:
let message = json["message"] as? String