xcode7.0以上版本需要在info上添加 App Transport Security Settings 类型为字典 在字典里面添加Allow Arbitrary Loads 布尔型 YES
从plist文件获取数据
NSBundle* boule=[NSBundle mainBundle];
NSString* path=[boule pathForResource:@"dddd" ofType:@"plist"];
NSDictionary * dic=[[NSDictionary alloc]initWithContentsOfFile:path];
NSMutableArray * arr=dic[@"name"];
//网络图片:(同步) NSString* string=@"http://api.k780.com:88/upload/weather/d/1.gif"; NSData * data = [NSData dataWithContentsOfURL:[NSURL URLWithString:string]]; UIImage *image =[ UIImage imageWithData:data]; //Json格式数据: 网络请求类型:
//同步 NSString* str=@"http://www.weather.com.cn/data/sk/101010100.html"; NSURL* url=[NSURL URLWithString:str]; NSURLRequest * request=[[NSURLRequest alloc]initWithURL:url]; NSData* data=[NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
//必须等data获取完之后才能执行下面代码 NSDictionary* dataDit=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:nil]; NSLog(@"%@",dataDit); //异步
NSString* string=@"资源地址";//比如图片资源
NSURL* url=[[NSURL alloc ]initWithString:string];
NSURLRequest* request=[[NSURLRequest alloc]initWithURL:url];
/*
第一个参数为请求对象
第二个参数为该异步请求所在线程执行的操作
第三个参数为异步请求够执行的代码块
*/
[NSURLConnection sendAsynchronousRequest:request queue:[[NSOperationQueue alloc]init] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
//本代码块的执行时机为:异步请求完成,取得响应的数据
//代码段第一个参数为响应对象,第二个为接收到的数据,第三个位错误对象
UIImage* img=[UIImage imageWithData:data];
NSLog(@"%@",connectionError);
}];
//本地JSON格式
NSString *dataFilePath =[[NSBundle mainBundle] pathForResource:@"data" ofType:@"json"];
NSData *data = [NSData dataWithContentsOfFile:dataFilePath];
NSDictionary *dataDictionary = [NSJSONSerialization JSONObjectWithData:data options: NSJSONReadingAllowFragments error:nil];
AFNetWorking
NSString* str=@"网络URL"; AFHTTPSessionManager* manager = [AFHTTPSessionManager manager]; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; manager.responseSerializer.acceptableContentTypes = [NSSet setWithObject:@"application/json"]; [manager POST:str parameters:nil success:^(NSURLSessionDataTask *task, id responseObject) { //string NSString *string1 = [[NSString alloc] initWithData:responseObject encoding:NSUTF8StringEncoding]; NSLog(@"aaa %@",string1); //数组字典都可用这个方法 NSArray* arr=[NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil]; NSLog(@"获取成功"); } failure:^(NSURLSessionDataTask *task, NSError *error) { NSLog(@"获取失败:%@",error); }];
判断空类型
if([_model.processMemo isKindOfClass:NSClassFromString(@"NSNull")]){
greeLabel.text=@" ";
}