-
NSData NSDate NSString NSArray NSDictionary 相互转化
-
-
- NSString *string = @"hello word";
- NSData *data = [string dataUsingEncoding:NSUTF8StringEncoding];
- NSArray *array = [NSArray arrayWithObjects:@"1",@"2",@"3",nil];
- NSString *dateString = @"19891123";
- NSDictionary *dic = [NSDictionary dictionaryWithObjectsAndKeys:
- @"hello", @"word",
- @"chen", @"lu",
- @"jin", @"mei",
- @"cerastes", @"hehe",nil];
-
- NSData *string2data = [string dataUsingEncoding:NSUTF8StringEncoding];
- NSLog(@"%@",string2data);
- NSString *data2String = [[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
- NSLog(@"dataString = %@",data2String);
-
-
- NSData *arry2data = [NSKeyedArchiver archivedDataWithRootObject:array];
- NSArray *data2arry = [NSKeyedUnarchiver unarchiveObjectWithData:arry2data];
- NSLog(@"%@ /n %@",arry2data,data2arry);
-
- NSDate *string2date = [self convertDateFromString:dateString withFormattre:@"yyyyMMdd"];
- NSLog(@"date = %@",string2date);
-
- NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
- [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
- NSString *date2string = [dateFormatter stringFromDate:[NSDate date]];
- NSLog(@"%@", date2string);
-
-
-
-
- NSString *arry2String = [array componentsJoinedByString:@" "];
-
- NSLog(@"string = %@",arry2String);
-
-
- NSArray *string2Arry = [arry2String componentsSeparatedByString:@" "];
- NSLog(@" %@",string2Arry);
-
-
-
- NSMutableData *dic2data = [[NSMutableData alloc] init];
- NSKeyedArchiver *archiver = [[NSKeyedArchiver alloc] initForWritingWithMutableData:dic2data];
- [archiver encodeObject:dic forKey:@"Some Key Value"];
- [archiver finishEncoding];
- NSLog(@"%@",dic2data);
-
- NSKeyedUnarchiver *unarchiver = [[NSKeyedUnarchiver alloc] initForReadingWithData:dic2data];
- NSDictionary *data2dic = [unarchiver decodeObjectForKey:@"Some Key Value"];
- [unarchiver finishDecoding];
- NSLog(@"%@",data2dic);
-
-
- NSString *dic2string=[dic JSONRepresentation];
- NSLog(@"%@",dic2string);
-
- NSError *error = nil;
- NSDictionary *string2dic = [NSJSONSerialization JSONObjectWithData: [dic2string dataUsingEncoding:NSUTF8StringEncoding]
- options: NSJSONReadingMutableContainers
- error: &error];
- NSLog(@"%@",string2dic);
-
相关阅读:
博客作业01-抽象数据类型
C语言最后一次作业--总结报告
C语言博客作业--函数嵌套调用
C语言博客作业--结构体
数位DP之奥义
POJ 3311 Hie with the Pie (状压DP)
kaungbin_DP S (POJ 3666) Making the Grade
POJ 3666 Making the Grade
kuangbin_SegTree M (HDU 4553)
kuangbin_SegTree I (HDU 1540)
-
原文地址:https://www.cnblogs.com/stephen-init/p/4295572.html
Copyright © 2020-2023
润新知