Ios AFP嵌套参数请求

Ios AFP嵌套参数请求,ios,objective-c,api,afnetworking,Ios,Objective C,Api,Afnetworking,我有一个rails api,可以生成位置和这些位置的菜单。在我的iOS应用程序中,我使用AFNetworking在表视图中检索这些位置的json列表 这是我用来获取位置数据的AFNetworking请求 LocationTableViewController.m [[LocationApiClient sharedInstance] getPath:@"locations.json" parameters:nil s

我有一个rails api,可以生成位置和这些位置的菜单。在我的iOS应用程序中,我使用AFNetworking在表视图中检索这些位置的json列表

这是我用来获取位置数据的AFNetworking请求

LocationTableViewController.m

[[LocationApiClient sharedInstance] getPath:@"locations.json" parameters:nil
                                        success:^(AFHTTPRequestOperation *operation, id response) {
                                            NSLog(@"Response: %@", response);
                                            NSMutableArray *results = [NSMutableArray array];
                                            for (id locationDictionary in response) {
                                                Location *location = [[Location alloc] initWithDictionary:locationDictionary];
                                                [results addObject:location];

                                            }
                                            self.results = results;
                                            [self.tableView reloadData];
                                        }
                                        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                            NSLog(@"Error fetching locations!");
                                            NSLog(@"%@", error);

                                        }];
[[LocationApiClient sharedInstance] getPath:@"locations/**(location_id from location table cell inserted here)**/beers.json" parameters:nil
                                        success:^(AFHTTPRequestOperation *operation, id response) {
                                            NSLog(@"Response: %@", response);
                                            NSMutableArray *results = [NSMutableArray array];
                                            for (id beerDictionary in response) {
                                                Beer *beer = [[Beer alloc] initWithDictionary:beerDictionary];
                                                [results addObject:beer];

                                            }
                                            self.results = results;
                                            [self.tableView reloadData];
                                        }
                                        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                            NSLog(@"Error fetching beers!");
                                            NSLog(@"%@", error);

                                        }];
为位置请求返回的json示例

 {
    "created_at" = "2013-02-23T19:25:26Z";
    id = 2;
    lat = "48.870175";
    long = "2.779899999999998";
    name = "Disneyland Hotel";
    "places_id" = fd90769e2cf40d6cb6cb1a3d0bfd0ce5d37ed331;
    "street_address" = "Rue de la Marni\U00e8re, Chessy, France";
    "updated_at" = "2013-02-23T19:25:26Z";
}, 
将显示名称和地址

当用户点击位置单元格时,我希望显示该位置列表的表视图。rails api路由(对于位置_id=>1)是
http://localhost:3000/locations/1/beers.json
并为属于位置id的啤酒输出以下json:1

    {
"created_at":"2013-02-23T19:25:53Z",
"description":"fkjgvjkg",
"id":1,"location_id":1,
"name":"nhoihioh",
"price":"2.5","style":"ipa",
"updated_at":"2013-02-23T19:25:53Z"
    }
当用户点击位置单元格时,我想显示该位置的啤酒列表,该列表通过
http://localhost:3000/locations/(与点击的表格单元格关联的任何位置\u id)/beers.json

当用户点击位置单元格时,如何将location_id插入下一个表视图中发生的以下AFNetworking请求中

BeerTableViewController.m

[[LocationApiClient sharedInstance] getPath:@"locations.json" parameters:nil
                                        success:^(AFHTTPRequestOperation *operation, id response) {
                                            NSLog(@"Response: %@", response);
                                            NSMutableArray *results = [NSMutableArray array];
                                            for (id locationDictionary in response) {
                                                Location *location = [[Location alloc] initWithDictionary:locationDictionary];
                                                [results addObject:location];

                                            }
                                            self.results = results;
                                            [self.tableView reloadData];
                                        }
                                        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                            NSLog(@"Error fetching locations!");
                                            NSLog(@"%@", error);

                                        }];
[[LocationApiClient sharedInstance] getPath:@"locations/**(location_id from location table cell inserted here)**/beers.json" parameters:nil
                                        success:^(AFHTTPRequestOperation *operation, id response) {
                                            NSLog(@"Response: %@", response);
                                            NSMutableArray *results = [NSMutableArray array];
                                            for (id beerDictionary in response) {
                                                Beer *beer = [[Beer alloc] initWithDictionary:beerDictionary];
                                                [results addObject:beer];

                                            }
                                            self.results = results;
                                            [self.tableView reloadData];
                                        }
                                        failure:^(AFHTTPRequestOperation *operation, NSError *error) {
                                            NSLog(@"Error fetching beers!");
                                            NSLog(@"%@", error);

                                        }];

我假设我必须记录location_id,并在点击表格单元格时将该值作为url的参数传递,但我不确定如何做到这一点。

在使用JSON时,您可能应该使用AFJSONRequestOperation,因为它会将的响应数据解析到字典中

AFJSONRequestOperation JSONRequestOperationWithRequest:request
                                                           success:^(NSURLRequest *request, NSHTTPURLResponse *response, id locationJSON) {

....

};
然后,您可以从字典中获取位置id,然后再打一个电话获取啤酒信息