ios--数据的临时保存形式

//创建多个字典
    PersonalModel *model=[[PersonalModel alloc]init];
    model.name=@"111";
    model.gender=@"男";
    model.PersonalPhoto=@"wwww/asd";
    
    NSMutableArray *array=[[NSMutableArray alloc]init];
    [array addObject:model];
    model.name=@"2222";
    
    [array addObject:model];
    array=[PersonalModel mj_keyValuesArrayWithObjectArray:array] ;
    
    NSData *jsondata=[NSJSONSerialization dataWithJSONObject:array options:(NSJSONWritingPrettyPrinted) error:nil];
    NSString *jsonString = [[NSString alloc] initWithData:jsondata encoding:NSUTF8StringEncoding];
    NSLog(@"转成json%@", jsonString);
    
    //回转
    NSMutableArray *oldArray=[NSJSONSerialization JSONObjectWithData:[jsonString dataUsingEncoding:NSUTF8StringEncoding] options:NSJSONReadingAllowFragments error:nil];
    oldArray=[PersonalModel mj_objectArrayWithKeyValuesArray:oldArray];
    NSLog(@"回成json%@", oldArray);
    for (PersonalModel *user in oldArray) {
        NSLog(@"name=%@, icon=%@", user.name, user.gender);
    }


使用到的框架:MJExtension.h

 
 

你可能感兴趣的:(ios)