需要从gitHub上下载JSONKit文件。也可以从我上传的资料上下载即可。
//1.获取文件路径
NSString *path = [[NSBundle mainBundle]pathForResource:@"JSON_StudentInfo" ofType:@"txt"];
//2.创建data对象
NSData *data = [[NSData alloc]initWithContentsOfFile:path];
//3.解析
NSArray *array = [data objectFromJSONData];
//4.组装
_array =[[NSMutableArray alloc]initWithCapacity:6];
for (NSDictionary *dict in array) {
Student *student = [Student new];
[student setValuesForKeysWithDictionary:dict];
[_array addObject:student];
}
//5.校验
for (Student *student in _array) {
NSLog(@"%@",student);
}