It’s hard to say for sure without seeing more of your code. Here’s a snippet of how you might send a basic JSON request to a server.
import Foundation
let json: [[String:String]] = [
[ "tick": "tock" ],
[ "bim": "bam" ]
]
let session = URLSession.shared
let url = URL(string: "http://example.com")!
var request = URLRequest(url: url)
request.setValue("application/json", forHTTPHeaderField: "Content-Type")
request.httpBody = try! JSONSerialization.data(withJSONObject: json, options: [])
let task = session.dataTask(with: request) { (responseBody, response, error) in
// … check `error` then check `response` then process `responseBody` …
}
task.resume()
You need to look at how your code sets the
httpBody
property. It seems like you’re serialising the in-memory objects to JSON data in some non-standard way.
Share and Enjoy
—
Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware
let myEmail = "eskimo" + "1" + "@apple.com"