NSDictionary *daiwei = @{
@"name":@"David Beckham",
@"age":@"38",
@"gender":@"true",
@"wife":@{
@"name":@"Victoria Beckham",
@"age":@(39),
@"team":@"Spice Girls"
},
@"children":@[
@"Brooklyn",@"Romeo",@"Cruz",@"Harper"]
};
// 从daiwei;里面找到children的值;放到nameList的数组里面;
NSArray *nameList = daiwei[@"children"];
// 盛方便小孩的数组(最终要把这个数组放到man对象childList属性里面)
NSMutableArray *childArray = [NSMutableArray array];
// 把小孩添加到childArray这个数组里面的过程;
for (NSString *name in nameList) {
ChildModel *child = [[ChildModel alloc]init];
child.name = name;
[childArray addObject:child];
// 每次初始化一个小孩放到childArray里面去,循环的;
}
NSLog(@"%@",childArray);
WIfeModei *wife = [[WIfeModei alloc]init];
wife.name = daiwei[@"wife"][@"name"];
wife.age = [daiwei[@"wife"][@"age"]intValue];
wife.team = daiwei[@"wife"][@"team"];
ManModei *man = [[ManModei alloc]init];
man.name = daiwei[@"name"];
man.age = [daiwei[@"age"]intValue];
man.ganrd = daiwei[@"gender"];
man.wife = wife;
man.childList = childArray;
NSLog(@"%@",man);
#import "WIfeModei.h"
@implementation WIfeModei
-(NSString *)description
{
return [NSString stringWithFormat:@"%@%d%@",self.name,self.age,self.team];
}
@end
#import <Foundation/Foundation.h>
@interface WIfeModei : NSObject
@property NSString *name;
@property int age;
@property NSString *team;
#import <Foundation/Foundation.h>
@interface ChildModel : NSObject
@property NSString *name;
@property NSString *team;
@property NSString *age;
#import "ChildModel.h"
@implementation ChildModel
- (NSString *)description
{
return self.name;
}
#import <Foundation/Foundation.h>
@class WIfeModei;
@interface ManModei : NSObject
@property NSString *name;
@property int age;
@property NSArray *childList;
@property WIfeModei *wife;
@property NSString *ganrd;
#import "ManModei.h"
@implementation ManModei
- (NSString *)description
{
return [NSString stringWithFormat:@"%@%d%@%@%@",self.name,self.age,self.childList,self.wife,self.ganrd];
}