iOS 字符串的UTF8 编码 以及归档反归档

 NSString* str = [@"%E4%B8%AD%E5%9B%BD" stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    

 NSLog(@"str=%@", str);

 

  

    NSString *str1 = @"中国";

    NSString *str2 = [str1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

    NSLog(@"str2 = %@",str2);

    

12.关于归档反归档

 

#warning 归档第一步:对student对象进行归档操作

    NSString *stuPath = [documentPath stringByAppendingPathComponent:@"student.av"];

    BOOL stuResult = [NSKeyedArchiver archiveRootObject:stu toFile:stuPath];

    if (stuResult) {

        NSLog(@"stu归档成功");

    }

#warning 归档第二步: 反归档取出文件中的数据

    Student *stu1 = [NSKeyedUnarchiver unarchiveObjectWithFile:stuPath];

    NSLog(@"name = %@, age = %ld, sex = %@", stu1.name, stu1.age, stu1.sex);

 

原文地址:https://www.cnblogs.com/fan-cong/p/4878449.html