Nsdictionary *daiwei = @{
@ "name": @ "David Beckham",
@ "Age": @ "38",
@ "Gender": @ "true",
@ "Wife": @{
@ "name": @ "Victoria Beckham",
@ "Age": @ (39),
@ "Team": @ "Spice Girls"
},
@ "Children": @[
@ "Brooklyn", @ "Romeo", @ "Cruz", @ "Harper"]
};
from Daiwei; Find the value of children; put it in the namelist array;
Nsarray *namelist = daiwei[@ "Children"];
An array of easy-to-reach children (this array is eventually placed in the Man Object Childlist property)
Nsmutablearray *childarray = [Nsmutablearray array];
The process of adding a child to the Childarray array;
For (NSString *name in NameList) {
Childmodel *child = [[Childmodel alloc]init];
Child.name = name;
[Childarray Addobject:child];
Each time a child is initialized and put into the childarray, it loops;
}
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];
}
objective-c-Data Model