It was working fine before but somehow i am getting above error now while converting NSData to String. It showing me error on line number 2 i.e
let jsonString = NSString(data: jsonData as Data, encoding: String.Encoding.utf8.rawValue) as! String
It shows me error.
cannot convert value of type 'Data' to expected argument type 'Data'
OR
cannot convert value of type 'NSData' to type 'Data' in coercion
do{
jsonData = try JSONSerialization.data(withJSONObject: para, options: JSONSerialization.WritingOptions()) as NSData
let jsonString = NSString(data: jsonData as Data, encoding: String.Encoding.utf8.rawValue) as! String
print("json array string best json request body = \(jsonString)")
return jsonString
} catch _ {
print ("UH OOO")
return nil
}
Too much NS and too much as, just use the native Swift structs
jsonData = try JSONSerialization.data(withJSONObject: para)
let jsonString = String(data: jsonData, encoding: .utf8)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With