• AFNetworking网上加载数据及JSON解析


    引用第三方库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]]; 

  • 相关阅读:
    Codeforces Round #394 (Div. 2) A. Dasha and Stairs
    HDU 1410 PK武林盟主
    HDU 3362 Fix(状压dp)
    P678-vect2.cpp
    Qt5获取本机网络信息
    Qt5标准文件对话框类
    nRF52832无法加载协议栈文件
    Debug记录(1)
    大小端模式
    nRF52832的SAADC
  • 原文地址:https://www.cnblogs.com/caolongs/p/4764740.html
Copyright © 2020-2023  润新知