how to prevent NSJSONSerialization from adding extra escapes in URL

前端 未结 5 719

How do I prevent NSJSONSerialization from adding extra backslashes to my URL strings?

NSDictionary *info = @{@\"myURL\":@\"http://www.example.com/test\"};
NS         


        
5条回答
  •  眼角桃花
    2020-11-29 09:44

    I have tracked this issue for many years, and it is still not fixed. I believe Apple will never fix it for legacy reasons (it will break stuff).

    The solution in Swift 4.2:

    let fixedString = string.replacingOccurrences(of: "\\/", with: "/")
    

    It will replace all \/ with /, and is safe to do so.

提交回复
热议问题