我正在尝试使用以下代码将字符串发送到 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/