@interface Model : NSObject
@property(nonatomic , strong)NSString *name;
@property(nonatomic , strong)NSString *start_time;
@property(nonatomic , strong)NSString *create_time;
@property(nonatomic , strong)NSString *describe;
@property(nonatomic , strong)NSString *type;
@end
表格
- (void)setvaluesModel:(Model*)model{
? ? if(model) {
? ? ? ? self.label1.text= model.name;
? ? ? ? self.label2.text= model.describe;
? ? ? ? self.label3.text= model.start_time;
? ? }
}
#import "ViewController.h"
#import "AFHTTPSessionManager.h"
#import "TableViewCell.h"
#import "Model.h"
#import "DataManager.h"
#import "Student+CoreDataClass.h"
#import "MJExtension.h"
- (void)Load{
? ? AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
? ? [managerGET:@"http://127.0.0.1/first.json"parameters:nilprogress:^(NSProgress*_NonnulldownloadProgress) {
? ? }success:^(NSURLSessionDataTask*_Nonnulltask,id? _NullableresponseObject) {
? ? ? ? self.array = [Model mj_objectArrayWithKeyValuesArray:responseObject];
? ? ? ? for(NSDictionary*dicinresponseObject) {
? ? ? ? ? ? [[DataManagershareManager]insert:dic];
? ? ? ? }
? ? ? ? [self.ojtablereloadData];
? ? }failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {
? ? ? ? NSLog(@"%@",error);
? ? }];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView*)tableView{
? ? returnarr.count;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
? ? if(section ==0) {
? ? ? ? return1;
? ? }else{
? ? ? ? returnself.array.count;
? ? }
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
? ? TableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
? ? if(self.array.count>0) {
? ? ? ? Model*model =self.array[indexPath.row];
? ? ? ? [cellsetvaluesModel:model];
? ? ? ? [cell.Btn addTarget:self action:@selector(StartBtn:)forControlEvents:UIControlEventTouchUpInside];
? ? ? ? [cell.Btn setTitle:@"開始考試" forState:UIControlStateNormal];
? ? ? ? cell.Btn.tag= indexPath.row;
? ? }
? ? returncell;
}
- (CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath{
? ? return 150;
}
- (NSString*)tableView:(UITableView*)tableView titleForHeaderInSection:(NSInteger)section{
? ? returnarr[section];
}
- (void)StartBtn:(UIButton*)btn{
}
- (void)tableView:(UITableView*)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath*)indexPath{
? ? Student*model =self.array[indexPath.row];
? ? [[DataManager shareManager]deleteData:model];
? ? [self.arrayremoveObject:self.array[indexPath.row]];
? ? [self.ojtable reloadData];
}
下面這個是POST解析
@interfaceImgModel :NSObject
@property(nonatomic,assign)NSDate *create_time;
@property(nonatomic,copy)NSString *id;
@property(nonatomic,copy)NSString *title;
@end
@interfaceDataModel :NSObject
@property(nonatomic,assign) int page;
@property(nonatomic,assign) int pages;
@property(nonatomic,copy) NSArray *list;
@end
@interface Model : NSObject
@property(nonatomic,assign) int code;
@property(nonatomic,strong) DataModel *data;
@end
#import "Model.h"
@implementation ImgModel
@end
@implementation DataModel
@end
@implementation Model
@end
#import "ViewController.h"
#import "Model.h"
#import "AFNetworking.h"
#import "MJExtension.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property(nonatomic,strong)NSArray *arr;
@property(nonatomic,strong)UITableView *tbv;
@end
@implementation ViewController
- (void)viewDidLoad {
? ? [super viewDidLoad];
? ? [self createNav];
? ? [self.viewaddSubview:self.tbv];
}
-(void)createNav{
? ? //2.發(fā)送GET請求
? ? /*
?? ? 第一個參數(shù):請求路徑(不包含參數(shù)).NSString
?? ? 第二個參數(shù):字典(發(fā)送給服務(wù)器的數(shù)據(jù)~參數(shù))
?? ? 第三個參數(shù):progress 進(jìn)度回調(diào)
?? ? 第四個參數(shù):success 成功回調(diào)
?? ? task:請求任務(wù)
?? ? responseObject:響應(yīng)體信息(JSON--->OC對象)
?? ? 第五個參數(shù):failure 失敗回調(diào)
?? ? error:錯誤信息
?? ? 響應(yīng)頭:task.response
?? ? */
? ? AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
? ? //參數(shù)
? ? NSMutableDictionary *params = [NSMutableDictionary dictionary];
? ? params[@"method"] = @"app.news.getarticlelist";
? ? params[@"class_id"] =@"3";
? ? params[@"_debug"] =@"Y";
? ? [managerPOST:@"http://test.bit.api.meeboo.cc"parameters:paramsprogress:nilsuccess:^(NSURLSessionDataTask*_Nonnulltask,id? _NullableresponseObject) {
? ? ? ? [DataModel mj_setupObjectClassInArray:^NSDictionary *{
? ? ? ? ? ? return@{
?? ? ? ? ? ? ? ? ? ? @"list":@"ImgModel"
?? ? ? ? ? ? ? ? ? ? };
? ? ? ? }];
? ? ? ? Model*model = [Modelmj_objectWithKeyValues:responseObject];
? ? ? ? self.arr= model.data.list;
? ? ? ? [self.tbvreloadData];
? ? ? ? NSLog(@"%@---%@",[responseObjectclass],responseObject);
? ? }failure:^(NSURLSessionDataTask*_Nullabletask,NSError*_Nonnullerror) {
? ? ? ? NSLog(@"請求失敗--%@",error);
? ? }];
}
-(UITableView *)tbv{
? ? if(!_tbv) {
? ? ? ? _tbv = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
? ? }
? ? _tbv.dataSource = self;
? ? _tbv.delegate=self;
? ? return _tbv;
}
-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
? ? return_arr.count;
}
-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath{
? ? UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
? ? if(!cell) {
? ? ? ? cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"cell"];
? ? }
? ? //cell.textLabel.text = [self.arr[indexPath.row] objectForKey:@"title"];
? ? ImgModel*mod=self.arr[indexPath.row];
? ? cell.textLabel.text= mod.title;
? ? returncell;
}
AFHTTPSessionManager *manager =[AFHTTPSessionManager manager];
? ? [manager GET:@"http://123.126.40.109:7003/asmr/videos/A1100101.shtml" parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
? ? } success:^(NSURLSessionDataTask * _Nonnull task, id? _Nullable responseObject) {
? ? ? ? //解析的是數(shù)組
? ? ? ? NSArray *dicArr = responseObject[@"result"];
? ? ? ? self.array = [NSArray yy_modelArrayWithClass:[Model class] json:dicArr];
? ? ? ? //解析是字典
//? ? ? ? Model *model = [Model yy_modelWithJSON:responseObject];
//? ? ? ? for (NSDictionary *dic in responseObject[@"result"]) {
//? ? ? ? ? ? Model *model = [Model new];
//? ? ? ? ? ? [model setValuesForKeysWithDictionary:dic];
//? ? ? ? ? ? [self.array addObject:model];
//? ? ? ? }
? ? ? ? [self.ojtable reloadData];
? ? } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
? ? ? ? NSLog(@"%@",error);
? ? }];
@end