When doing a GET (using Postman) request from my backend the string looks like this:
"En kort information om Passalen\r\n\r\nSer bra ut va? :)"
But after using this command to get the string:
let about = try moyaResponse.mapString()
Moya will transform the string and it will look like this:
\"En kort information om Passalen\\r\\n\\r\\nSer bra ut va? :)\"
How can I have the string unmodified?
Anyone?
Not sure, it looks like the \ in the original string are getting escaped – sometimes this happens with print. I've never used Postman, how are you getting the value returned from mapString()?
What do you mean how I'm getting the value?
I'm just doing this:
do {
let about = try moyaResponse.mapString()
} catch {
print(error)
}
And you're just using print(about)? I'm just wondering if it's actually working but print is doing something weird.
No I'm debugging the code and checking the value of about
Yes looks like the original '\' are getting escaped and also the '"'
Do you have a solution for this?
I don't, I'm sure there are solutions to this. mapString's source code is pretty straightforward, this could be something with Alamofire. To be honest I'm not sure which direction you should go in, I would look up issues on Alamofire's repository and google how to prevent double-escaping. Sorry for not having a more satisfactory answer, please let us know how it goes 👍
Seems that the response I got was content-type json so when I used mapJson() instead it was parsed correctly. Thanks for your help!
Glad you got it sorted out, and thanks for following-up with the solution 👍 I'm sure it'll be of help to others.
Most helpful comment
Seems that the response I got was content-type json so when I used mapJson() instead it was parsed correctly. Thanks for your help!