注:本教程只含字典轉模型使用方法
來看下這個結構有沒有你想要的
NSDictionary *bigDic =@{@"banner":
@{@"url":@"urllllll",
@"pic":@"picccccc",
@"id":@"banner33333"},
@"list":
@[@{@"name":@"商店一",
@"id":@"id11111"},
@{@"name":@"商店二",
@"id":@"id22222"}],
@"det":@"detttt",
@"ha":@"haaaaaaa",
@"dictCont":
@{
@"CLASS":@[
@{
@"CBA":@"CBA1",
@"TV":@"CCTV1",
@"TBQ":@"TBQ1"
}
],
@"QWER":@{
@"TM":@"TM1",
@"HN":@"HN1"
},
@"SB":@[@"SB1",
@"SB2",
@"SB2"]
}
};
- 口訣來一套
字典建Model,數組看內容 (看到字典就建Model,看到數組根據數組內容來決定)
數組含字典,繼續建Model (數組內只含有字典,就根據數組內的字典繼續建Model)
-
數組含其他,放那兒不用管 (數組內如果不是字典,就幾乎不用管了)
23333333
Code
- 這個就是最簡單的解析
BIGModel *bigModel = [BIGModel yy_modelWithDictionary:bigDic];
- 這個是model內屬性名和字典內鍵值不一致時的方法
+ (NSDictionary *)modelCustomPropertyMapper
{
return @{@"dicContArrModel":@"dictCont"};
}
- 這個方法是對model內屬性的一個解釋吧
+ (NSDictionary *)modelContainerPropertyGenericClass
{
return @{
@"banner":[BannerModel class],
@"list":[ShopModel class],
@"dicContArrModel":[DictContArrModel class]
};
}