NSData与其它类型的转换

NSString转换成NSData对象

NSData *xmlData = [@"testdata" dataUsingEncoding:NSUTF8StringEncoding];

NSData转换成NSString对象

NSData *data;

NSString *result = [NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

NSData转换成Char*

NSData *data;

char *test = [data bytes];

Char*转换成NSData

byte *tempData = malloc(sizeof(byte)*16);

NSData *content = [NSData dataWithBytes:tempData length:16];

posted on 2015-12-04 10:38  Fs_purple  阅读(86)  评论(0编辑  收藏  举报