我创建了一个附带loginViewController.swift的简单登录屏幕。我有简单的登录api。它在post man web服务上显示响应的web服务没有使用alamofire在xcode上显示序列化的json输出。如何从url获取序列化json。
et url="http://192.169.201.32:9000//users/authenticate" ?the api is getting two parameters from username ="andrews" and password="admin2".
let url="http://192.168.100.11:9000//users/authenticate"
override func viewDidLoad() {
super.viewDidLoad()
Alamofire.request(url, method: .post, parameters:["username":"andrews","password":"admin2"], encoding: JSONEncoding.default)
.responseJSON { response in
/////is it correct way to enter the parameter??
print("abcsign in")
print(response)
//to get status code
if let status = response.response?.statusCode {
switch(status){
case 201:
print("example success")
default:
print("error with response status: \(status)")
}
}
//to get JSON return value
if let result = response.result.value {
let JSON = result as! NSDictionary
print("abcsign in 2")
print(JSON)
}
}
[self .boaderSetting()]
username_input.text = "andrews"
password_input.text = "admin2"
[self .login_now(username:"andrews", password:"admin2")]
let preferences = UserDefaults.standard
if preferences.object(forKey: "session") != nil
{
login_session = preferences.object(forKey: "session") as! String
check_session()
}
else
{
LoginToDo()
}
}
如何将序列化的json输出到Ns日志?你可以从这个链接下载项目。https://drive.google.com/file/d/1h3TMFkpyOdCB_SoLYdca5Jmh4vulL7t_/view?usp=sharing
答案 0 :(得分:0)
使用URLEncoding代替JSONEncoding将解决您的问题