API未使用Alamofire显示串行的JSON输出



我已经创建了使用loginviewController.swift附加的简单登录屏幕。我有简单的登录API。它正在显示在Post Man Web服务上显示响应的Web服务未在Xcode上使用Alamofire显示串行的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日志上?/div>

使用urlencoding而不是jsonencoding将解决您的问题

相关内容

  • 没有找到相关文章

最新更新