Why doesn't this work?
let jsonResponse = " \"This is a response\" "
let str = try! JSONDecoder().decode(String.self, from: jsonResponse)
print(str)
error: cannot convert value of type 'String' to expected argument type 'Data'
In other languages, like javascript or java/kotlin, converting this response into a string is pretty easy.
JS
const s = JSON.parse(" \"This is a response\" ")
Kotlin
val s = Gson().fromJson(String::class.java, " \"This is a response\" ")
But in swift, it doesn't seem this straight forward. Is this response valid json? I assumed that the double quotes would make it a valid json object.
Thanks in advance.