标签:
1 #import "YSHomeViewController.h" 2 #import "UIImage+YS.h" 3 #import "UIBarButtonItem+YS.h" 4 #import "YStitleButton.h" 5 #import "AFNetworking.h" 6 #import "YSaccountTool.h" 7 #import "YSaccount.h" 8 #import "UIImageView+WebCache.h" 9 #import "YSStatus.h" 10 #import "YSUser.h" 11 #import "MJExtension.h" 12 @interface YShomeViewController() 13 @property(nonatomic,strong)NSArray *statuses; 14 @end 15 @implementation YShomeViewController 16 17 -(void)viewDidLoad 18 { 19 [super viewDidLoad]; 20 [self setUpNavBar]; 21 [self setUpWeiboList]; 22 23 } 24 -(void)setUpWeiboList 25 { 26 AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager]; 27 NSMutableDictionary *param = [NSMutableDictionary dictionary]; 28 YSaccount *account = [YSaccountTool account]; 29 30 param[@"access_token"] = account.access_token; 31 // param[@"count"] = @99; 32 [mgr GET:@"https://api.weibo.com/2/statuses/home_timeline.json" parameters:param success:^(AFHTTPRequestOperation *operation, id responseObject) { 33 NSArray *dictArray = responseObject[@"statuses"]; 34 35 //高级技术.运行时.字典转模型 36 self.statuses = [YSStatus mj_objectArrayWithKeyValuesArray:dictArray]; 37 [self.tableView reloadData]; 38 } failure:^(AFHTTPRequestOperation *operation, NSError *error) { 39 40 }]; 41 }
1 //// 2 //// YSStatus.h 3 //// ysWeibo 4 //// 5 //// Created by ys on 15/12/3. 6 //// Copyright (c) 2015年 ys. All rights reserved. 7 //// 8 // 9 //#import <Foundation/Foundation.h> 10 //@class YSUser; 11 //@interface YSStatus : NSObject 12 ///** 13 // * 微博的内容(文字) 14 // */ 15 //@property (nonatomic, copy) NSString *text; 16 ///** 17 // * 微博的来源 18 // */ 19 //@property (nonatomic, copy) NSString *source; 20 ///** 21 // * 微博的ID 22 // */ 23 //@property (nonatomic, copy) NSString *idstr; 24 ///** 25 // * 微博的转发数 26 // */ 27 //@property (nonatomic, assign) int reposts_count; 28 ///** 29 // * 微博的评论数 30 // */ 31 //@property (nonatomic, assign) int comments_count; 32 ///** 33 // * 微博的作者 34 // */ 35 //@property (nonatomic, strong) YSUser *user; 36 //@end 37 #import "YSStatus.h" 38 @implementation YSStatus 39 40 @end
1 //// 2 //// YSUser.h 3 //// ysWeibo 4 //// 5 //// Created by ys on 15/12/3. 6 //// Copyright (c) 2015年 ys. All rights reserved. 7 //// 8 // 9 //#import <Foundation/Foundation.h> 10 // 11 //@interface YSUser : NSObject 12 ///** 13 // * 用户的ID 14 // */ 15 //@property (nonatomic, copy) NSString *idstr; 16 ///** 17 // * 用户的昵称 18 // */ 19 //@property (nonatomic, copy) NSString *name; 20 ///** 21 // * 用户的头像 22 // */ 23 //@property (nonatomic, copy) NSString *profile_image_url; 24 //@end 25 26 #import "YSUser.h" 27 28 @implementation YSUser 29 30 @end
字典转模型的三种方法之三:MJExtension全自动字典模型互转
标签:
原文地址:http://www.cnblogs.com/yangshun-work/p/5018959.html