JSONKit解析
2015-09-27 11:25
519 查看
#import "ViewController.h" #import "JSONKit.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSString *urlString = @"https://api.douban.com/v2/book/search?q=s"; [NSURLConnection sendAsynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]] queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) { //json解析 NSDictionary *dic = [data objectFromJSONData]; #if 0 NSString *string ; //json解析 [string objectFromJSONString]; #endif NSLog(@"%@",dic[@"total"]); }]; /* username : "test" password : "xxx" other : {"key1":"value1","key2":["test","test2"]} */ NSDictionary *dic = @{ @"key1":@"value1", @"key2":@[@"test",@"test2"] }; //提交到服务器的是json字符串 //系统把对象(NSArray,NSDic)转化为json字符串 NSData *data = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:nil]; NSString *string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]; /* TestString:NSString TestString *s; */ //判断string是否是NSString类或者其子类 if ([string isKindOfClass:[NSString class]]) { NSLog(@"YES"); } //判断string是否是NSString类。不包括子类 [string isMemberOfClass:[NSString class]]; NSLog(@"--- %@",string); #if 0 /* 在运行的时候和编译的时候data3是什么类型; 编译是NSData; 运行是NSString */ NSData *data3 = [[NSString alloc] init]; [data3 isEqualToData:[NSData data]]; #endif } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } @end
相关文章推荐
- JavaScript高级程序设计之引用类型之单体内置对象之Global对象第5.7.1讲笔记
- JavaScript 闭包
- JS实现带鼠标效果的头像及文章列表代码
- 通过超链接传值到jsp页面,用el表达式获取时中文乱码
- 关于voller框架的json image netimage
- html 自动生成数字------document.write(c) js写在 html里面
- javascript 比量str今天的日期是,参数diff
- JS实现仿新浪黄色经典滑动门效果代码
- JavaScript作用域以及闭包(一)
- JS将滑动门改为选项卡(需鼠标点击)的实现方法
- js定时器
- js动态生成树形结构
- JavaScript验证正则表达式大全
- CSS和JavaScript标签style属性对照表(用javascript来控制css不再难了)
- Javascript与iframe的那些事儿
- JS操作JSON总结
- JS对象序列化为JSON对象
- 浅谈javascript的Touch事件
- Ember.js 入门指南——路由切换的防止和重试
- impress.js