[英]Convert NSArray into NSData iOS objective-c
这是我的代码,但我无法获取数据
NSData *wrtData = [NSKeyedArchiver archivedDataWithRootObject:my_Array];
If you want to convert a NSArray
to NSData
you should make sure that all objects inside this array conform to NSCoding protocol . 如果要将NSArray
转换为NSData
,则应确保该数组内的所有对象均符合NSCoding协议 。 Same goes for NSDictionary
. NSDictionary
。
Use this sample: 使用此示例:
NSArray *mapPoints = @[
@{ @"latitude":@"10.010490",
@"longitude":@"76.360779",
@"altitude":@"30.833334",
@"timestamp":@"11:17:23",
@"speed":@"0.00",
@"distance":@"0.00"
},
@{
@"latitude":@"10.010688",
@"longitude":@"76.361378",
@"altitude":@"28.546305",
@"timestamp":@"11:19:26",
@"speed":@"1.614",
@"distance":@"198.525711"
}
];
NSLog(@"Countries array = %@",mapPoints);
NSData *mapPointsData = [NSKeyedArchiver archivedDataWithRootObject:mapPoints];
NSLog(@"countries data=%@",mapPointsData);
NSLog(@"mapPointsData to mapPointsArray = %@",[NSKeyedUnarchiver unarchiveObjectWithData:mapPointsData]);
https://github.com/k-sathireddy/JsonArrayToNSData https://github.com/k-sathireddy/JsonArrayToNSData
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.