zoukankan      html  css  js  c++  java
  • iOS--关于同步下载

    {
    
       NSMutableArray *_dataList;
    }
    
    [self loadDataWithPage:1];
        
    [self loadDataWithURLConnection];
    
     
    
    //记得初始化数组
    
    _dataList =[NSMutableArray array];
    
     
    
     
    
    -(void)loadDataWithURLConnection
    {
        //创建URL对象
        NSURL *url =[NSURL URLWithString:@"http://iappfree.candou.com:8080/free/applications/limited//?currency=rmb&page=1"];
        //创建网络请求对象
        NSURLRequest  *request =[[NSURLRequest alloc]initWithURL:url cachePolicy:NSURLRequestReturnCacheDataElseLoad timeoutInterval:10];
        //同步请求数据
        NSHTTPURLResponse *response;
        NSData *data =[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
      //  NSLog(@"data=%@",data);
        //请求数据成功. code=200;
      //  NSLog(@"code =%li",response.statusCode);
        id Json =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        // NSLog(@"%@",Json);
        if ([Json isKindOfClass:[NSDictionary class]]) {
            //字典方法解析
            NSArray *applications =[Json objectForKey:@"applications"];
            NSLog(@"%@",applications);
            _dataList =[applications mutableCopy];
        }else if ([Json isKindOfClass:[NSArray class]]){
            //数组方法解析
        }
    }
    //从网络请求数据
    -(void)loadDataWithPage:(NSInteger)pageIndex
    {
        NSString *URLString =[NSString stringWithFormat:@"http://iappfree.candou.com:8080/free/applications/limited//?currency=rmb&page=%li",pageIndex];
        NSURL *url =[NSURL URLWithString:URLString];
        //读取网址内容为字符串对象
        NSString *dataString =[NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];
        //把字符串转换成NSData对象
        NSData *data =[dataString dataUsingEncoding:NSUTF8StringEncoding];
        //把直接把网址内容读取成NSData对象
       // NSData *data =[NSData dataWithContentsOfURL:url];
       // NSLog(@"%@",data);
        id Json =[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
       // NSLog(@"%@",Json);
        if ([Json isKindOfClass:[NSDictionary class]]) {
            //字典方法解析
            NSArray *applications =[Json objectForKey:@"applications"];
           // NSLog(@"%@",applications);
            _dataList =[applications mutableCopy];
        }else if ([Json isKindOfClass:[NSArray class]]){
            //数组方法解析
        }
    }
  • 相关阅读:
    框架-.NET:Spring.Net
    杂项-WebService:WebService
    公司-企业内部创业:企业内部创业
    公司-内部创业:内部创业
    架构-软件系统体系结构-B/S架构:B/S架构
    架构-软件系统体系结构-C/S架构:C/S架构
    android google map v1 v2 v3 参考
    选购好的主机和服务器可以有效提高优化效果
    u盘安装ubuntu10.04 、11.04 server
    IOS学习笔记45--UITableView性能优化
  • 原文地址:https://www.cnblogs.com/LQCQ-Silent/p/4890117.html
Copyright © 2011-2022 走看看