iOS 字典和NSData之间转换

释放双眼,带上耳机,听听看~!
//字典转NSData:
+(NSData *)returnDataWithDictionary:(NSDictionary*)dict
{
    NSMutableData *data = [[NSMutableData alloc]init];
    NSKeyedArchiver* archiver = [[NSKeyedArchiver alloc]initForWritingWithMutableData:data];
    [archiver encodeObject:dict forKey:@"talkData"];
    [archiver finishEncoding];
    return data;
}

//NSData 转字典:
// NSData转dictonary
+(NSDictionary*)returnDictionaryWithDataPath:(NSData*)data
{
    //  NSData* data = [[NSMutableData alloc]initWithContentsOfFile:path]; 拿路径文件
    NSKeyedUnarchiver* unarchiver = [[NSKeyedUnarchiver alloc]initForReadingWithData:data];
    NSDictionary* myDictionary = [unarchiver decodeObjectForKey:@"talkData"];
    [unarchiver finishDecoding];
    return myDictionary;
}

 

人已赞赏
iOS文章

获取UISearchBar上的UITextField

2019-11-16 23:37:10

iOS文章

iOS 时间戳转时间

2019-11-17 5:43:58

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
有新消息 消息中心
搜索