Simple objective-c GET request

后端 未结 4 1600
栀梦
栀梦 2020-12-13 04:17

Most of the information here refers to the abandoned ASIHTTPREQUEST project so forgive me for asking again.

Effectively, I need to swipe a magnetic strip and send th

4条回答
  •  执笔经年
    2020-12-13 05:15

    **Simply Call and get your JSON Data.**
    
    -(void)getJSONData
    {
    
    NSURL *url = [NSURL URLWithString:@"http://itunes.apple.com/us/rss/topaudiobooks/limit=10/json"];
    
    NSURLSession *session = [NSURLSession sharedSession];
    
    NSURLSessionDataTask *data = [session dataTaskWithURL:url completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
    
        NSError *erro = nil;
    
        if (data!=nil) {
    
            NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&erro ];
    
            if (json.count > 0) {
    
                for(int i = 0; i<10 ; i++){
    
                    [arr addObject:[[[json[@"feed"][@"entry"] objectAtIndex:i]valueForKeyPath:@"im:image"] objectAtIndex:0][@"label"]];
               }
    
            }
        }
        dispatch_sync(dispatch_get_main_queue(),^{
    
            [table reloadData];
        });
    }];
    
    [data resume];
    }
    

提交回复
热议问题