Don't record JSONSerealization

Hi, I'm problem, when I add this line: request.addValue("application/json", forHTTPHeaderField: "Content-Type")

To be able to see in the output, it doesn't write, but when I take this line of code, it writes.

My code: URLSession.shared.dataTask(with: request) { data, response, error in

                if error == nil {

                    guard let data = data else {return}

                    

                    guard let json = try? JSONSerialization.jsonObject(with: data, options: .allowFragments) else{

                        return

                    }

                    print("Sucesso")

                    print(json)

                    

                    /*DispatchQueue.main.async(execute: {

                        do {

                        }catch {

                            

                        }

                    })*/

                        

                    

                } else {

                    print("Sem sucesso!")

                }

            } .resume()

To be able to see in the output, it doesn't write, but when I take this line of code, it writes.

Please clarify “doesn’t write”? Are you saying that the request sent to the server doesn’t include the Content-Type header? Or that something goes wrong with the JSON processing code in your completion handler?

If it’s the latter, please provide more details about what goes wrong. If you step through the code in the debugger, what lines execute?


ps You’re more likely to get answers if you spend a little more time crafting your post. Specifically:

  • Please use a code block for code snippets.

  • Please tag your questions appropriately. Forums Feedback is not the right place for this question (-: I move it over to Foundation, which is the framework that contains the APIs you’re using.

You can find lots of hints about using DevForums in Quinn’s Top Ten DevForums Tips.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Don't record JSONSerealization
 
 
Q