ios获取远程json数据

    NSMutableArray *arr;
    arr = [[NSMutableArray alloc]init];//全局
    
    NSURL *url = [NSURL URLWithString:@"http://a.meidebi.com/Link-alllist-p-1-pagecount-10"];//获取网络资源
    
    NSURLRequest *request = [NSURLRequest requestWithURL:url];//建立一个请求
    
    NSURLResponse *response = nil;
    
    NSError *error = nil;
    
    //网络连接转换为数据类型
    
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
    
    //用NSJSONSerialization把JSON数据解析成UI类型
    
    id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
    
    NSDictionary *dic = (NSDictionary *)jsonObject;
    
    //NSLog(@"%@",dic);
    
    NSDictionary *dic1 = [dic valueForKey:@"data"];
    
    NSDictionary *dic2 = [dic1 valueForKey:@"linklist"];
    
    
    
    for (NSDictionary *dic3 in dic2) {
        
        [arr addObject:[dic3 objectForKey:@"title"]];
        
    }

 

 
posted @ 2014-01-15 23:24  haiwei.sun  阅读(666)  评论(0编辑  收藏  举报
返回顶部