NSOperation,jason解析,UIWebView等相关使用

IOS 练习
涉及到优酷API使用,NSOperation,jason解析,UIWebView等相关使用
//  
//  ViewController.m
//  NSURLrequest
//
//  Created by apple on 15/5/4.
//  Copyright (c) 2015年 apple. All rights reserved.
//
#import "ViewController.h"
@interface ViewController () <UIWebViewDelegate>
@property (nonatomic,strong) UIWebView *webView;
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
   
    
    NSOperationQueue *qu = [NSOperationQueue mainQueue];
    
    
    NSURLRequest *req = [NSURLRequest requestWithURL:[NSURL URLWithString:@"https://openapi.youku.com/v2/videos/show_basic.json?video_id=XOTI2NjczMjUy&client_id=29089327c6ecc3f4"]];
//    NSData *data = [NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
    
    [NSURLConnection sendAsynchronousRequest:req queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError*connectionError) {
        if (!data){
            return ;
            
        }
//        NSLog(@"%@",data);
        NSDictionary *n1 = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
//        NSLog(@"%@",n1);
        NSLog(@"%@",n1[@"link"]);
       
        _webView = [[UIWebView alloc] initWithFrame:CGRectMake(0, 20, 320, 480)];
        _webView.delegate = self;
        _webView.scalesPageToFit = YES;
        [self.view addSubview:_webView];
        
        _webView.backgroundColor = [UIColor redColor];
        NSLog(@"over");
        [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:n1[@"link"]]]];
//        [_webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://v.youku.com/v_show/id_XOTI2NjczMjUy.html"]]];
        
    }];
    // https://openapi.youku.com/v2/videos/show_basic.json?video_id=XOTI2NjczMjUy&client_id=29089327c6ecc3f4
    
    
    // https://openapi.youku.com/v2/videos/show_basic.json?video_id=XOTM1NTMyNDA4&client_id=b10ab8588528b1b1
    
//    NSDictionary *n1 = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil];
  
    
    
    
    
    
    
  
}
@end

你可能感兴趣的:(NSOperation,jason解析,UIWebView等相关使用)