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 Kickstart.

SPONSORED You know how to code. Now learn how to ship. My new app focuses on everything around your app that actually determines success, bringing together your App Store listing, competitor research, pricing, reviews, analytics, marketing, and launch workflow so you're never figuring it out alone.

Download Kickstart here

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