step 1: Create pods and copy Alamofire pod in podfile using stackoverflow and github.
step 2: Following step 1 to 6 of JSON Serialization code.
step 7: Create function of Alamofire. Like,
step 2: Following step 1 to 6 of JSON Serialization code.
step 7: Create function of Alamofire. Like,
func get_call_API_Alamofire() {
Alamofire.request("URL", method: .get, parameters: nil, encoding: JSONEncoding.default, headers: nil).responseJSON { (response) in
if response.error == nil {
self.json_Data = response.value as! NSDictionary
print("JSON Alamofire Data:",self.json_Data)
self.tbl_view.reloadData()
}
else
{
print("Error=",response.error!.localizedDescription)
}
}
}
step 8 to 10 is of JSON Serialization code.
POST Method of Alamofire.
POST Method of Alamofire.
func postParametersAlamofir(){
if let url = URL(string: "URL") {
var request = URLRequest(url: url)
request.httpMethod = "POST"
let postString : String = "StudentId=2011111"
request.httpBody = postString.data(using: String.Encoding.utf8)
Alamofire.request(request).responseJSON(completionHandler: { (response) in
print(response.value as! NSDictionary)
})
}
}
(Call this function on ViewDidLoad)
Thank you...
No comments:
Post a Comment