Tag: afjsonrequestoperation

如何使用AFJSONRequestOperation返回一个响应对象

我试图通过使用AFJSONRequestOperation获取天气数据。 问题是我不能在查询完成时返回对象。 有没有人知道如何做到这一点? 我目前的实施是 – (NSDictionary *)getCityWeatherData:(NSString*)city { NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://free.worldweatheronline.com/feed/weather.ashx?key=xxxxxxxxxxxxx&num_of_days=3&format=json&q=%@", city]]; NSURLRequest *request = [NSURLRequest requestWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { NSDictionary *data = [[JSON objectForKey:@"data"] objectForKey:@"weather"]; return data; } failure:nil]; [operation start]; }

AFNetworking版本2内容types错误

我试图做一个iphone应用程序,将与特定的JIRA服务器进行交互。 我有以下代码login: NSURL *url = [[NSURL alloc] initWithString:@"https://mycompany.atlassian.net/rest/auth/latest/session/"]; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url]; [request setHTTPMethod:@"POST"]; NSString *postString = [NSString stringWithFormat:@"{\"username\":\"%@\",\"password\":\"%@\"}", username, password]; [request setHTTPBody:[postString dataUsingEncoding:NSUTF8StringEncoding]]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [request setValue:@"application/json" forHTTPHeaderField:@"Accept" ]; operation.responseSerializer = [AFJSONResponseSerializer serializer]; [operation setCompletionBlockWithSuccess: ^(AFHTTPRequestOperation *operation, id responseObject) { NSLog(@"JSON: %@", responseObject); } failure:^(AFHTTPRequestOperation *operation, NSError *error) { […]

replaceAFNetworking 2.x中的AFJSONRequestOperation

我正在做一个基本的iPhone应用程序与HTML请求,按照本教程。 本教程让我在AFNetworking中使用AFJSONRequestOperation。 麻烦的是,我正在使用AFNetworking版本2,它不再有AFJSONRequestOperation。 所以,当然,这个代码(从教程中的“ 查询iTunes StoresearchAPI ”标题下的大约一半)不能编译: NSURL *url = [[NSURL alloc] initWithString: @"http://itunes.apple.com/search?term=harry&country=us&entity=movie"]; NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url]; AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) { NSLog(@"%@", JSON); } failure:^(NSURLRequest *request, NSHTTPURLResponse *response, NSError *error, id JSON) { NSLog(@"Request Failed with Error: %@, %@", error, error.userInfo); }]; [operation start]; […]