首页 > Web开发 > 详细

AFNetworking网上加载数据及JSON解析

时间:2015-08-27 22:48:23      阅读:333      评论:0      收藏:0      [点我收藏+]

 

引用第三方库AFNetworking

#import "AFNetworking.h"

#import "UIKit+AFNetworking.h"

- (void)downloadData
{
    NSString *urlString = [NSString stringWithFormat:LIMIT_URL,_page,_categoryId];
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.responseSerializer = [AFHTTPResponseSerializer serializer];
    [manager GET:urlString parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        //JSON解析数据
        NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        NSArray *apps = dict[@"applications"];
        for (NSDictionary *appDict in apps) {
            AppModel *model = [[AppModel alloc] init];
            [model setValuesForKeysWithDictionary:appDict];
            model.desc = appDict[@"description"];
            [_dataArray addObject:model];

            [self.tableView reloadData];//若刷新表格需在block块内
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}

通过AFNetworking,使用url从网上加载图片(#import "UIKit+AFNetworking.h")

 [cell.iconImageView setImageWithURL:[NSURL URLWithString:model.iconUrl]]; 

 

AFNetworking网上加载数据及JSON解析

原文:http://www.cnblogs.com/caolongs/p/4764740.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!