jesonModel 的简单使用

本文将介绍如何使用Objective-C语言进行iOS应用开发的基本步骤和关键概念,包括环境搭建、基本语法、UI设计与交互、数据存储与管理等核心内容。通过实践示例,帮助开发者快速上手iOS开发。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

这里给出了大致的思路 只是个基础 大家还要多使用 
这个库需要自己下载并引入 即可使用
#import "ViewController.h"
#import "itemModel.h"

@interface ViewController ()
/**
 *      NSString* urlStr1 = @"http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=3";
 */
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    NSString* urlStr = @"http://iappfree.candou.com:8080/free/applications/limited?currency=rmb&page=3";
    
    NSURL *url = [NSURL URLWithString:urlStr];
    
    [self downloadTask:url];
    
    // Do any additional setup after loading the view, typically from a nib.
}

-(void)downloadTask:(NSURL *)url{
    NSURLRequest *request = [NSURLRequest requestWithURL:url];
    NSURLSession *session = [NSURLSession sharedSession];
    NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
        //取到最外层字典
        NSDictionary *dictjeson = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
        //取到字典里面的applications 数据
        NSArray *applications = [dictjeson objectForKey:@"applications"];
        for(NSDictionary *dict in applications)
        {
            itemModel *item = [[itemModel alloc]initWithDictionary:dict error:nil];
            NSLog(@"item:%@",item);
            NSLog(@"%@",item.toJSONString);
        }
    }];

    //任务执行
    [dataTask resume];
    NSString *json = @"{\"applicationId\": \"757752585\",\"slug\": \"puzzle-chef\",\"name\": \"美味厨房\",\"releaseDate\": \"2014-09-17\",\"version\": \"1.3.0\"}";
    
    //能够自动检测key 的正确性
    itemModel *model = [[itemModel alloc]initWithString:json usingEncoding:NSUTF8StringEncoding error:nil];
    
    NSLog(@"------------model-------------%@",model);
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值