0

当我调用 Google API 获取地址并在这里调用 api 时。

-(void)searchviews:(NSString*)EditString selector:(SEL)sel
{  
    NSLog(@"Welcome To Search views");

    searchviews=sel;
     NSString *path =[NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?address=%@&sensor=false",EditString]; 

    NSURL *url=[NSURL URLWithString:path];
    NSLog(@"hiii---%@",url);
    ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
    [request setRequestMethod:@"POST"];
    [request setDelegate:self];
    [request startAsynchronous];
    [drkSignUp showWithMessage:nil];
    NSLog(@" Complet--------------- "); 

对于我称之为请求方法的请求方法。

- (void)requestFinished:(ASIHTTPRequest *)request {

    //NSLog(@"%@",[request responseString]);

    NSString *func = [self getFunc:[request url]];

    NSLog(@"%@\n%@",func,[request responseString]);

 if ([func isEqual:@"json?address=%@&sensor=false"]) 
            {
                NSDictionary *resDict = [parser objectWithString:[request responseString] error:nil];
                NSLog(@"---- ResData%@",resDict);
                NSString *result = [resDict objectForKey:@"successful"];
                NSLog(@"hiiiii google api calling............");

                [drkSignUp hide];
                [self.delegate performSelector:searchviews withObject:[resDict objectForKey:@"results"]]; 

就是这样,但问题在乐趣中产生。当我打电话时

if ([func isEqual:@"json?address=%@&sensor=false"])

它不是调用 cos 而是动态字符串。那么我应该在 func 中放置什么来代替 %@ ?

4

1 回答 1

0

您可以填写如下的 userInfoASIFormDataRequest字典

//After this line
ASIFormDataRequest *request=[ASIFormDataRequest requestWithURL:url];
//Add 
request.userInfo = [NSDictionary dictionaryWithObject:@"EditString" forKey:@"request"];

然后在

- (void)requestFinished:(ASIHTTPRequest *)request {
    //Get the request userInfo
    NSString *str = [request.userInfo objectForKey:@"request"];
    //now fill the request string
    NSString *requestString = [NSString stringWithFormat:@"json?address=%@&sensor=false", str];
    //Check it with func
    if ([func isEqual:requestString]) 
    {
        //Continue your procedure
    }
}
于 2012-06-18T05:56:52.817 回答