您的位置:首页 > 移动开发 > IOS开发

iOS GET方式进行同步请求

2015-12-30 18:26 211 查看
define ZQGETUEL @”http://ipad-bjwb.bjd.com.cn/DigitalPublication/publish/Handler/APINewsList.ashx?date=20131129&startRecord=1&len=5&udid=1234567890&terminalType=Iphone&cid=213

(void)GetSyncAction{

//网络请求

//1.生成URL

NSURL *url = [NSURL URLWithString:CQGETUEL];

//2.创建请求对象,绑定URL

NSMutableURLRequest *requst = [[NSMutableURLRequest alloc] initWithURL:url];

//3.发送请求

NSData *data = [NSURLConnection sendSynchronousRequest:requst returningResponse:nil error:nil];

NSLog(@”%@”, data);

//JSon 解析

NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:nil];

NSArray *arr = dic[@”news”];

self.data = [NSMutableArray array];

for (NSDictionary *dic in arr) {

News *news = [[News alloc] init];

[news setValuesForKeysWithDictionary:dic];

[self.data addObject:news];

}

//循环打印检查

for (News *news in self.data) {

NSLog(@”%@–%@–%ld”, news.title, news.NId, news.sequence);

}

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  ios GET同步