Convert UTF-8 encoded NSData to NSString

前端 未结 7 801
佛祖请我去吃肉
佛祖请我去吃肉 2020-11-22 08:43

I have UTF-8 encoded NSData from windows server and I want to convert it to NSString for iPhone. Since data contains characters (like a degree symb

7条回答
  •  北海茫月
    2020-11-22 09:04

    Sometimes, the methods in the other answers don't work. In my case, I'm generating a signature with my RSA private key and the result is NSData. I found that this seems to work:

    Objective-C

    NSData *signature;
    NSString *signatureString = [signature base64EncodedStringWithOptions:0];
    

    Swift

    let signatureString = signature.base64EncodedStringWithOptions(nil)
    

提交回复
热议问题