NSString 和Base64的互相轉(zhuǎn)換
- base64 => NSData => NSString 解碼
NSData *data = [[NSData alloc] initWithBase64EncodedString:stringBase64 options:0];
NSString *string =[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
- NSString => NSData => base64 編碼
NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
NSString *stringBase64 = [data base64EncodedStringWithOptions: NSDataBase64EncodingEndLineWithCarriageReturn];
網(wǎng)絡(luò)訪(fǎng)問(wèn)請(qǐng)求url中:中文空格特殊字符等的編碼解碼
- 編碼
stringByAddingPercentEscapesUsingEncoding
- 解碼
stringByRemovingPercentEncoding
- 案例:
{
//編碼:URL包含中文字符和空格等涩嚣,需要轉(zhuǎn)義
urlStr = [urlStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
}
{
// 解碼
urlStr = [urlStr stringByRemovingPercentEncoding];
}