NEW: Download Kickstart, the app that helps indie developers succeed on the App Store! >>

API JSON

Forums > SwiftUI

How can i take off out (sorry my english) of the function the responseJSON in a array?

    func fazLogin (username: String, password: String) -> [String: Any]?? {

        let json: [String: Any] = [
            "username": "\(username)",
            "password": "\(password)"
        ]

                let jsonData = try? JSONSerialization.data(withJSONObject: json)

                // create post request
                let url = URL(string: "xxxxxxxx")! //PUT Your URL
                var request = URLRequest(url: url)
                request.httpMethod = "POST"
                request.setValue("\(String(describing: jsonData?.count))", forHTTPHeaderField: "Content-Length")
                request.setValue("application/json", forHTTPHeaderField: "Content-Type")
                // insert json data to the request
                request.httpBody = jsonData

                let task = URLSession.shared.dataTask(with: request) { data, response, error in
                    guard let data = data, error == nil else {
                        print(error?.localizedDescription ?? "No data")
                        return
                    }
                    let responseJSON = try? JSONSerialization.jsonObject(with: data, options: [])
                    if let responseJSON = responseJSON as? [String: Any] {
                        print(responseJSON) //Code after Successfull POST Request
                    }
                }

                task.resume()
    }
}

3      

Hacking with Swift is sponsored by Swiftsonic.

SPONSORED It's the final countdown! Swiftsonic is an all-new event for Swift developers taking place in Nashville, November 20–22. Build alongside fellow Swift and iOS developers with practical talks, the best in AI, fresh ideas, and conversations that make you pumped to ship again. So what are you waiting for? Get your pass and let’s dial the volume up to 11!

Learn more

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account