Objective c 将NSDictionary转换为NSInputStream

Objective c 将NSDictionary转换为NSInputStream,objective-c,nsdictionary,nsinputstream,Objective C,Nsdictionary,Nsinputstream,可以将我的NSDictionary放入NSInputStream吗? 这将是我的字典 NSArray *keys = [NSArray arrayWithObjects:@"name", @"device_token", @"identifier", nil]; NSArray *values = [NSArray arrayWithObjects:@"Test iPhone", initDeviceToken, [UIDevice currentDevice].uniqueIdentifier

可以将我的NSDictionary放入NSInputStream吗? 这将是我的字典

NSArray *keys = [NSArray arrayWithObjects:@"name", @"device_token", @"identifier", nil];
NSArray *values = [NSArray arrayWithObjects:@"Test iPhone", initDeviceToken, [UIDevice currentDevice].uniqueIdentifier, nil];
NSDictionary *parameters = [NSDictionary dictionaryWithObjects:values forKeys:keys];
我试过这样的方法,但是没有用

NSInputStream *inputStream = [[NSInputStream alloc] init];
[inputStream setValue:@"123" forKey:@"identifier"];

Thx很多

当然。方法是使用
NSPropertyListSerialization
将字典序列化为
NSData
对象,然后将数据对象写入
NSInputStream

缺点是,这要求您的字典只保存plist对象(数字、字符串、日期、数据、数组和字典)。

任何符合的对象都是可序列化的,因此可写入流。当然,容器对象中的项也必须符合NSCoding协议