项目中如果采用ICE请求数据的结构,有时候后台会传送以NSData形式的long数组。下方法可以直接转成Byte数组或者是OC数组。
-(NSArray *) convertDataToLongArrayWithData:(NSData *)data{
long *longdata;
long *longtemp;
int longnum = (int)[data length]/sizeof(long);
longdata = (long*)[data bytes];
NSMutableArray *tempArray = [NSMutableArray array];
for(int i=0; i<longnum; i++) {
longtemp = longdata + i;
NSLog(@"longtemp = %ld", *longtemp);
NSString * longStr = [NSString stringWithFormat:@"%ld",*longtemp];
[tempArray addObject:longStr];
}
return tempArray;
}
再附把Byte数组转成NSData方法
//需要将long数组转换成NSData类型
long a[]= {204678129343320064,204653186857619456};
NSData *data1 = [NSData dataWithBytes: &a length: sizeof(a)];