BOOL b;
@
try {
NSURL *url=[NSURL URLWithString:urlString];
NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:url];
request.timeoutInterval=30;
[request setHTTPMethod:@"GET"];
NSHTTPURLResponse *response=nil;
NSError *error=nil;
NSData *data=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSInteger a= [response statusCode];
NSLog(@"ResponseState=%ld",a);
if (a!=200 || error) {
NSLog(@"Exception=%@",@"网络错误异常!!!!");
b = NO;
}
else{
//json 解析
id json=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSLog(@"请求返回的 json 数据为%@",json);
//TO DO
//得到 json
b = YES;
}
}
@
catch (NSException *exception) {
NSLog(@"调用堆栈=%@",exception.callStackSymbols);
NSLog(@"Exception=%@",@"这是异常!");
NSLog(@"Exception=%@",exception.description);
b = NO;
}
@
finally {
return b;
}