将 NSArray 转换为 NSData iOS objective-c

Convert NSArray into NSData iOS objective-c

这是我的代码,但我无法获取数据

NSData *wrtData = [NSKeyedArchiver archivedDataWithRootObject:my_Array];

如果要将 NSArray 转换为 NSData,您应该确保此数组中的所有对象都符合 NSCoding protocolNSDictionary.

也是如此

使用这个示例:

   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]);

Github link:

https://github.com/k-sathireddy/JsonArrayToNSData