jesonModel 的简单使用
来源:互联网 发布:如何在爱淘宝上推广 编辑:程序博客网 时间:2024/06/01 19:48
这里给出了大致的思路 只是个基础 大家还要多使用 这个库需要自己下载并引入 即可使用#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
0 0
- jesonModel 的简单使用
- 简单易懂的使用
- ant的简单使用
- Log4j的简单使用
- TCPDUMP的简单使用
- IComparer的简单使用
- TreeView的简单使用
- CListCtrl的简单使用
- Rose的简单使用
- OpenSSL的简单使用
- CInternetSession的简单使用
- 标签的简单使用
- 触发器的简单使用
- nekohtml的简单使用
- FileUpload的简单使用
- JFreeChart的简单使用
- JMX的简单使用
- Vi的简单使用
- 向DataGrid、DropDownList控件添加数据
- Ubuntu 12.04 安装之后的各种问题
- vs2012编译lua源代码
- 树莓派做 wifi 热点
- Ice::SocketException { error = 13 }
- jesonModel 的简单使用
- js判断 pc端 移动端
- java中类名+方法名(){}什么意思?
- 360测试开发
- 对敏感文件读取问题
- linux中printk的使用方法
- 禁用返回手势
- 白话空间统计十五:多距离空间聚类分析 (Ripley's K 函数) (下)
- 用画图板画出一个心形