how to prevent NSJSONSerialization from adding extra escapes in URL

前端 未结 5 726

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:38

    If your target is >= iOS 13.0, then just add .withoutEscapingSlashes to the options.

    Example:

    let data = try JSONSerialization.data(withJSONObject: someJSONObject, options: [.prettyPrinted, .withoutEscapingSlashes])
    
    print(String(data: data, encoding: String.Encoding.utf8) ?? "")
    

提交回复
热议问题