【发布时间】:2015-01-29 20:27:20
【问题描述】:
我可以使用以下代码访问我的 API url 并接收 json 数据,但是我需要使用以下参数和值指定要请求的数据。我该怎么做?
参数: q 值:追逐
参数:页面值:1
NSMutableURLRequest *request3 = [[NSMutableURLRequest alloc] init];
[request3 setValue:@"application/json;charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[request3 setURL:[NSURL URLWithString:@"https://MYWEBSITE.com/api/v1/intuit/institutions"]];
[request3 setHTTPMethod:@"GET"];
NSURLResponse *requestResponse3;
NSData *requestHandler3 = [NSURLConnection sendSynchronousRequest:request3 returningResponse:&requestResponse3 error:nil];
NSError *err3;
NSMutableDictionary *json3 = [NSJSONSerialization JSONObjectWithData:requestHandler3 options:kNilOptions error:&err3];
NSLog(@"%@", json3);
【问题讨论】:
-
不相关,但通常异步方法(例如
sendAsynchronousRequest或任何NSURLSession方法)优于sendSynchronousRequest。
标签: objective-c json api get request