首先把MJExtension 第三方文件拖入到工程里面 Model类和View类里面照常写东西 View里面用xib照常拖
然后在VC.m里面引入#import “AFNetworking/AFNetworking.h”
#import “MJExtension/MJExtension.h”
#import “Model.h” 头文件
主要就是那一行代码
//数组包子店
self.dataSource = [Model mj_objectArrayWithKeyValuesArray:responseObject[@"T1348647853363"]];
/* ================ 字典包数组==============
// [mjmodel mj_setupObjectClassInArray:^NSDictionary *{
// return @"类的数组属性":[字典对应的model class ];
// }];
*/
接下来是解析部分
-(void)createAFN{
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
[manager GET:@"http://c.m.163.com/nc/article/headline/T1348647853363/0-20.html" parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
//数组包子店
self.dataSource = [Model mj_objectArrayWithKeyValuesArray:responseObject[@"T1348647853363"]];
/* ================ 字典包数组==============
// [mjmodel mj_setupObjectClassInArray:^NSDictionary *{
// return @"类的数组属性":[字典对应的model class ];
// }];
*/
[self.tbv reloadData];
NSLog(@"JSON: %@", responseObject);
} failure:^(NSURLSessionTask *operation, NSError *error) {
NSLog(@"Error: %@", error);
}];
}
其他部分照常写