#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

//[self takeRequestUrlWithString:@"http://127.0.0.1/test.json"];

//[self takeRequestUrlWithString:@"http://www.baidu.com"];

}

-(void)takeRequestUrlWithString:(NSString*)str

{

NSURL *url=[NSURL URLWithString:str];

NSURLRequest *request=[NSURLRequest requestWithURL:url cachePolicy:1 timeoutInterval:15];

[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {

if(!connectionError)

{

NSHTTPURLResponse *httpResponse=(NSHTTPURLResponse*)response;

if (httpResponse.statusCode==200) {

NSError *error=nil;

//返回的要么是字典要么是数组

id needData=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];

if(error)

{

NSLog(@"JSON 解析出错:%@",error);

}

else{

NSLog(@"模型转换:数据为:%@",needData);

}

}

else

{

NSLog(@"服务器出错 ,错误码:%ld",httpResponse.statusCode);

}

}

else{

NSLog(@"连接错误!!!");

}

}];

}

@end

@interface RYDataModel : NSObject

@property(nonatomic,strong)NSNumber *age;

@property(nonatomic,copy)NSString*name;

@property(nonatomic,strong)NSDictionary*school;

+(instancetype)dataWithDict:(NSDictionary*)dict;

@end

@implementation RYDataModel

+(instancetype)dataWithDict:(NSDictionary*)dict

{

RYDataModel *model=[RYDataModel new];

[model setValuesForKeysWithDictionary:dict];

return model;

}

@end

最新文章

  1. Stack操作,栈的操作。
  2. CsvHelper支持List<T>
  3. Taylor定理证明
  4. JAVA手记 JAVA入门(安装+Dos下运行)
  5. redis操作
  6. Sublime Text 使用 Emmet 补全错误问题
  7. Poj/OpenJudge 1042 Gone Fishing
  8. C学习-fgets()篇1
  9. Java的自定义注解使用实例
  10. MySql分割字符串【存储过程】
  11. 使用 WeihanLi.Npoi 操作 CSV
  12. linux 下 mac 地址如何查询
  13. 解析如何实现微信唤醒默认浏览器下载app教程!
  14. [转]Angular: Hide Navbar Menu from Login page
  15. Linux 简介(day1)
  16. darknet源码解析
  17. CSS基本知识(慕课网)
  18. bitnami redmine安装、配置、备份、恢复
  19. Spring之核心容器bean
  20. Mysql储存过程8:repeat循环

热门文章

  1. ASP.NET MVC中viewData、viewBag和templateData的使用与区别
  2. linux重定向
  3. [C#] 图文解说调用WebServer实例
  4. 69个经典Spring面试题和答案
  5. 用File判断D盘下面是否还有txt文件
  6. centos7下 安装mysql
  7. 10月28日上午 PHP数据访问
  8. 20145204&20145212信息安全系统实验一
  9. Java Web学习笔记3
  10. 1JavaEE应用简介----青软S2SH(笔记)