I am fetching data from an API using OAuth for authorization. I have successfully fetched the data I'm interested in and want to parse the result. It is not possible to convert the response to JSON format or a dictionary.
I have tried using OAuthSwift (https://github.com/OAuthSwift/OAuthSwift):
// do your HTTP request without authorize
oauthswift?.client.get(myURL) { result in
switch result {
case .success(let response):
do{
//here dataResponse received from a network request
let jsonResponse = try JSONSerialization.jsonObject(with:
response.data, options: [])
print(jsonResponse) //Response result
} catch let parsingError {
print("Error", parsingError)
}
print(response.string)
case .failure(let error):
print(error)
}
}
In this case response is in the format OAuthSwiftResponse which I can access .data from (Data)
My problem is that I cannot do JSONSerialization with the data, I get this error message:
JSON text did not start with array or object and option to allow fragments not set." UserInfo={NSDebugDescription=JSON text did not start with array or object and option to allow fragments not set
I want to have a dictionary with the result to be able to get specific values from the JSON object. Thanks in advance!