1. self.dataArray= [MJModel mj_objectArrayWithKeyValuesArray:data[@"resultMessage"][@"result"]];//data[@"resultMessage"][@"result"]解析出来的数组 /* 和上边的方法作用相同 NSArray *array=data[@"resultMessage"][@"result"];//解析出来的数组 for (NSDictionary *dic in array) { MJModel *modle=[MJModel mj_objectWithKeyValues:dic]; [self.dataArray addObject:modle]; } */ 2. NSArray * shopsArray = [shopModel objectArrayWithFilename:@"1.plist"]; [self.shops addObjectsFromArray:shopsArray];
1.简单的字典 --> 模型
- 核心代码
mj_objectWithKeyValues:
@interface User : NSObject @property (copy, nonatomic) NSString *name;/* 姓名 */ @property (assign, nonatomic) unsigned int age;/* 年龄 */ @end //简单的字典 NSDictionary *dict_user = @{ @"name" : @"Jack", @"age" : @20, }; User *user = [User mj_objectWithKeyValues:dict_user];
JSON字符串 --> 模型
-
// 定义一个JSON字符串 NSString *json = @"{\"name\":\"Jack\", \"icon\":\"lufy.png\", \"age\":20}"; User *user = [User mj_objectWithKeyValues:json];
//其他用法可以参考 http://www.jianshu.com/p/475b28160c89
时间: 2024-10-02 23:06:16