当尝试在字符串中包含 " 时,使用 \" 有效但 \ 也包含在内

When trying to include " in a String, using \" works but the \ is included too

我正在尝试使用以下代码将字符串发送到 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 [=14=] (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\", quantity: 2}.

的原因