标签:
无需其他类库
1: - (IBAction)callapi:(id)sender {
2: NSURL *url=[NSURL URLWithString:@"http://..."];
3: NSURLRequest *request=[NSURLRequest requestWithURL:url];
4: [NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
5: //json
6: NSDictionary *r=[NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
7: int cnt=[r count];
8: NSLog(@"%d",cnt);
9: [self resultlbl].text=[NSString stringWithFormat:@"%d",cnt];
10:
11: //string
12: //NSString *str=[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
13: //NSLog(str);
14: //[self resultlbl].text=r[0][0];
15: }];
16: }
标签:
原文地址:http://www.cnblogs.com/czcz1024/p/4537895.html