xcode - 当尝试包含 "in a String, using\"时有效但\也包含在内

标签 xcode string swift string-formatting

我正在尝试使用以下代码将字符串发送到 Http 请求

var outStr = "{product_code: \"660825\", quantity: \(qty)}"

因为我包含了\字符,所以它编译正常,但是当我运行它时,outStr 的值是

{product_code: \"660825\", quantity: 2}

我做错了什么,我怎么会失去\?

最佳答案

如你所见in the documentation :

String literals can include the following special characters:

The escaped special characters \0 (null character), \ (backslash), \t (horizontal tab), \n (line feed), \r (carriage return), \" (double quote) and \' (single quote)

(剪断)

let wiseWords = "\"Imagination is more important than knowledge\" - Einstein"
// "Imagination is more important than knowledge" - Einstein

你做得对,我的猜测是你的服务器将 " 转义为 \" 这就是你看到 {product_code:\"660825\", 数量:2}.

关于xcode - 当尝试包含 "in a String, using\"时有效但\也包含在内,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30865390/

相关文章:

c++ - cppunit 和 xcode 项目的 vtable 问题

ios - 适用于 iOS 的 FBSDK : "unrecognized selector sent to instance"

java - println() 方法中的字符串连接

python - 如何将unicode字符串拆分为列表

ios - 在 UIViewController 之间传递 UILongPressGestureRecognizer

cocoa - 如何调试仅在启用断点时在主循环之前崩溃的 Cocoa 应用程序?

objective-c - 将数据存储在 MKAnnotation 中?

java - 文件读取期间无限循环且 String.split() 无法正常工作

arrays - 如何查看图像数组中的下一张图像?

swift - 如何从 Swift 访问 Bluemix Conversation 变量