I am writing a simple full stack app and I made the return from the backend to be, in certain cases, just like an array of strings like below:
["one","two","three"]
The problem I am having now is that this return can't be parsed in swift like usual JSON data. I searched but found nothing. What I am trying to do is :
let json = try JSONSerialization.jsonObject(with: data!, options: [.mutableContainers, .allowFragments]) as? [String]
Unfortunately, this doesn't work at all How can I parse this just like a normal array?
Thanks in advance.
UPDATE: I am adding some more relevant code below:
let task = URLSession.shared.dataTask(with: request as URLRequest){
data, response, error in {
do {
let json = try JSONSerialization.jsonObject(with: data!, options: [.mutableContainers, .allowFragments]) as? [String]
print(json)
}catch{
print(error)
}
}
datatask.resume()
The error I am getting in the console is "Error Domain=NSCocoaErrorDomain Code=3840 "Invalid value around character 0." UserInfo={NSDebugDescription=Invalid value around character 0.}"
Thanks for all of you.
datacome from? What is the actual value you are trying to parse?