【问题标题】:Xcode-9 OR iOS 11 - replacing double quote with \" not workingXcode-9 或 iOS 11 - 用 \" 替换双引号不起作用
【发布时间】:2017-11-06 10:00:15
【问题描述】:

正如下面代码中提到的那样,我用转义字符替换双引号。相同的代码在 iOS 10.x 中运行良好,但在 iOS 11 中无法运行。

NSString *searchStr = [searchBar.text stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];

NSString *searchInput = [[NSString alloc] initWithFormat:@"{\"@type\": \"com.xyz.rest.find.SearchQuery\",\"value\": \"%@\"}", searchStr];

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[searchInput dataUsingEncoding:NSUTF8StringEncoding]];

任何线索将不胜感激!!!!

提前致谢

【问题讨论】:

  • 你能展示一些示例文本吗
  • 试图将“Cool”转换为“\”Cool\””以传递帖子正文。
  • 只使用json编码兄弟
  • 我想你没有得到问题,请检查更新的代码!

标签: ios ios10 ios11


【解决方案1】:

这可能是因为 iOS 11 中引入了智能标点符号。请查看以下链接。

https://www.reddit.com/r/apple/comments/778otd/ios_11_no_longer_encodes_double_quotes_as_the/

【讨论】:

  • 谢谢 kishan,这是智能标点的问题。
  • 欢迎@BhaveshPatel。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-09-23
  • 1970-01-01
  • 2021-08-12
  • 1970-01-01
  • 2017-04-09
相关资源
最近更新 更多