how to prevent NSJSONSerialization from adding extra escapes in URL

前端 未结 5 728

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

    Yeah, this is quite irritating and even more so because it seems there's no "quick" fix to this (i.e. for NSJSONSerialization)

    source:
    http://www.blogosfera.co.uk/2013/04/nsjsonserialization-serialization-of-a-string-containing-forward-slashes-and-html-is-escaped-incorrectly/
    or
    NSJSONSerialization serialization of a string containing forward slashes / and HTML is escaped incorrectly


    (just shooting in the dark here so bear with me)
    If, you're making your own JSON then simply make an NSData object out of a string and send it to the server.
    No need to go via NSJSONSerialization.

    Something like:

    NSString *strPolicy = [info description];
    NSData *policyData = [strPolicy dataUsingEncoding:NSUTF8StringEncoding];
    

    i know it won't be so simple but... hm... anyways

提交回复
热议问题