Moya: mapString() adds extra quotes and backslashes

Created on 24 Oct 2016  ·  9Comments  ·  Source: Moya/Moya

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?

question

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!

All 9 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

GurpalRajput picture GurpalRajput  ·  3Comments

Tynox picture Tynox  ·  3Comments

hamada147 picture hamada147  ·  3Comments

JoeFerrucci picture JoeFerrucci  ·  3Comments

geraldeersteling picture geraldeersteling  ·  3Comments