同步get获取所关注的最新微博

#import <Foundation/Foundation.h>

@interface WeiBoModle : NSObject
@property(nonatomic,strong)NSArray *statuses;
@property(nonatomic,strong)NSArray *advertises;
@property(nonatomic,strong)NSArray *ad;
@property(nonatomic,strong)NSNumber *hasvisible;
@property(nonatomic,strong)NSNumber *previous_cursor;
@property(nonatomic,strong)NSNumber *next_cursor;
@property(nonatomic,strong)NSNumber *total_number;
@property(nonatomic,strong)NSNumber *interval;
@property(nonatomic,strong)NSNumber *uve_blank;
@property(nonatomic,strong)NSNumber *since_id;
@property(nonatomic,strong)NSNumber *max_id;
@property(nonatomic,strong)NSNumber *has_unread;

-(id)initWithDictionary:(NSDictionary *)dictionary;

@end


#import "WeiBoModle.h"

@implementation WeiBoModle
-(id)initWithDictionary:(NSDictionary *)dictionary
{
    if (self = [super init])
    {
        
        [self setValuesForKeysWithDictionary:dictionary];
    }
    return self;
}
@end


#import "ViewController.h"
#import "WeiBoModle.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
}

//同步get
- (IBAction)synchronousGet:(id)sender {
    //拿到url
    NSString *urlString = @"https://api.weibo.com/2/statuses/home_timeline.json?access_token=2.00bUKyMDhwQ3UD584ae943a1b3KGwC";
    //编码
    urlString = [urlString stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
    //转换成NSURl
     NSURL *url = [NSURL URLWithString:urlString];
   // 创建并返回一个URL请求,指向一个指定的URl,采用对应的缓存策略 和 超市相应时长
   NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
    //在oc中使用   NSURLConnection类,和服务器连接,这里就是同步连接
    NSURLResponse *httpUrlResponse;
    NSError *error;
  NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&httpUrlResponse error:&error];
    //Json数据格式解析,利用系统提供的API进行Json数据解析
   NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];
    WeiBoModle *weiBo = [[WeiBoModle alloc]initWithDictionary:dictionary];
    self.TextView.text = [weiBo.statuses[0] objectForKey:@"text"];
    
    
    
}


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值