I am trying to encode my jsonData. All works fine with one exception - I am receiving as output Optional(my_json_string). But I want to receive only my_json_string
When I change req.httpBody = jsonData to req.httpBody! = jsonData, I am getting an error.
do {
let jsonData = try encoder.encode(self)
let jsonString = String(data: jsonData, encoding: .utf8)
req.httpBody = jsonData
print ("httpBody is: ", jsonString)
} catch {
//TODO:error handling
}
How to do it correctly and unwrap my JSON string from optional?