【发布时间】:2016-08-30 16:48:54
【问题描述】:
字符串中的反斜杠有问题。
当我用这段代码创建一个字符串时:
let url = webProtocol + siteHost + "/tables/coupon?$expand=source&$filter=Source/Name eq '" + category + "'&" + siteApi
我希望这个网址
https://swoup.azurewebsites.net/tables/coupon?$expand=source&$filter=Source/Name eq 'Recommended'&ZUMO-API-VERSION=2.0.0
但我明白了
https://swoup.azurewebsites.net/tables/coupon?$expand=source&$filter=Source/Name eq \'Recommended\'&?ZUMO-API-VERSION=2.0.0
我尝试使用
删除它们stringByReplacingOccurrencesOfString("\\", withString: "")
但这无济于事。我也尝试在 ' 之前添加反斜杠,但它没有帮助。
【问题讨论】:
-
为什么你期望的 URL 中有空格?
-
你对url编码了吗?
-
提供完整的问题,
webProtocol、siteHost、category和siteApi未定义。提供minimal reproducible example,强调完成。 -
正如 Aaron 指出的,您尝试创建的 URL 无效,空格和您使用的其他一些字符无效。在此处检查 URL 中的有效字符 -> stackoverflow.com/questions/1547899/…
-
您在哪里/如何记录 URL?许多工具显示转义版本并添加反斜杠。
标签: ios swift xcode string encoding