我有这个网址NSURL *url = [NSURL URLWithString:@"http://site.com/ArcGIS/rest/services/POI_Data/MapServer/0/query?&where=ToegangsNr+%3D+5002&returnGeometry=true&outSR=4326&f=json"];

但是我想使用NSUserdefault _phonenumber更改字符串中的5002值。

我怎样才能做到这一点?

此函数的其他代码是:

ASIHTTPRequest *_request = [ASIHTTPRequest requestWithURL:url];
__weak ASIHTTPRequest *request = _request;

request.requestMethod = @"POST";
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request appendPostData:[json dataUsingEncoding:NSUTF8StringEncoding]];
// 5
[request setDelegate:self];
[request setCompletionBlock:^{
    [MBProgressHUD hideHUDForView:self.view animated:YES];

    NSString *responseString = [request responseString];
    NSLog(@"Response: %@", responseString);
    [self plotCrimePositions:request.responseData];

}];
[request setFailedBlock:^{
    [MBProgressHUD hideHUDForView:self.view animated:YES];
    NSError *error = [request error];
    NSLog(@"Error: %@", error.localizedDescription);
}];

最佳答案

    NSURL *url = [NSURL URLWithString:@"http://site.com/ArcGIS/rest/services/POI_Data/MapServer/0/query?&where=ToegangsNr+%3D+5002&returnGeometry=true&outSR=4326&f=json"];
NSString *urlString = [url absoluteString];
urlString = [urlString stringByReplacingOccurrencesOfString:@"5002" withString:[userDefaults objectForKey:@"_phoneNumber"]];
NSLog(@"%@",urlString);
url = [NSURL URLWithString:urlString];
NSLog(@"%@",url);


希望对您有所帮助。

关于ios - 如何将NSUserdefault的值放在URL中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13379394/

10-13 00:17