2011-08-17 54 views
0
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.krsconnect.no/community/api.html?method=bareListEventsByCategory&appid=620&category-selected=350&counties-selected=Vest-Agder,Aust-Agder 

NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://www.krsconnect.no/community/api.html?method=bareListEventsByCategory&appid=620&category-selected=catId&counties-selected=Vest-Agder,Aust-Agder"]]; 

NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil]; 
NSString *json_string = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 
NSDictionary *object = [parser objectWithString:json_string error:nil]; 
NSArray *results = [parser objectWithString:json_string error:nil]; 

我有這個網址我想,類別選擇= 350應變量獲得價值如何做到這一點 我做的,但沒有得到結果,如果我給VAR名稱,而不是350如何在URL傳遞一個字符串值,在iPhone應用程序

回答

0

你可以試試這個:

NSURL *url = [NSURL URLWithString:[NSString stringWithFormat:@"http://www.businessfactors.de/bfcms/images/stories/videos/%@.mp4",strtext]]; 
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; 
0

使用NSString stringWithFormat與伊娃格式化的網址:

NSString *catId = @"350"; 
NSString *url = [NSString stringWithFormat:@"http://www.krsconnect.no/community/api.html?method=bareListEventsByCategory&appid=620&category-selected=%@&counties-selected=Vest-Agder,Aust-Agder", catId]; 
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:url]]; 
+0

我可以把所有的URL中的NSString – ali

+0

- [NSCFNumber長]:無法識別的選擇發送到實例0x9307c60 這是給異常,當我使用這個 – ali

+0

如果你的參數是一個整數,你應該使用%d參數而不是%@。請參閱[Apple格式指南](http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/Strings/Articles/formatSpecifiers.html#//apple_ref/doc/uid/TP40004265-SW1) –

0

發送使用stringByURLEncode,stringByURLDecode

- (NSString *)stringByURLDecode { 

     NSMutableString *tempStr = [NSMutableString stringWithString:self]; 
     [tempStr replaceOccurrencesOfString:@"+" withString:@" " options:NSCaseInsensitiveSearch range:NSMakeRange(0, [tempStr length])]; 

     return [[NSString stringWithFormat:@"%@",tempStr] stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    } 

    - (NSString *)stringByURLEncode { 

     NSMutableString *tempStr = [NSMutableString stringWithString:self]; 
     [tempStr replaceOccurrencesOfString:@" " withString:@"+" options:NSCaseInsensitiveSearch range:NSMakeRange(0, [tempStr length])]; 


     return [[NSString stringWithFormat:@"%@",tempStr] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

    } 
相關問題