2009-10-27 6 views
0

J'appelle un service Web pour renvoyer des données XML pour les états/provinces des pays.XML analyse URL question

- (void)viewDidLoad { 
[super viewDidLoad]; 

NSString *titleForURL = self.navigationItem.title; 
NSString *path =[NSString stringWithFormat:@"http://myURL/AppointmentWS/CountryStateService.asmx/GetByCountryName?countryName=%@", titleForURL]; 
//NSString *path [email protected]"http://myURL/CountryStateService.asmx/GetByCountryName?countryName=Canada"; 

UIApplication* app = [UIApplication sharedApplication]; 
app.networkActivityIndicatorVisible = YES; 

if ([statesData count] == 0) { 

    NSLog(path); 
    [self parseXMLFileAtURL:path]; 
} 

Si je mets explicitement le paramètre countryName, cela ne pose aucun problème. Mais si j'utilise le spécificateur de format de chaîne, j'obtiens un code d'erreur 5

Je pense que cela peut avoir à faire avec la façon dont l'URL est encodée?

Pensées?

Répondre

0

Quelle ligne génère l'erreur? Cela ressemble à parseXMLFileAtURL. Si c'est le cas, je regarderais les deux URL possibles et les comparerais.

NSString *path =[NSString stringWithFormat:@"http://myURL/AppointmentWS/CountryStateService.asmx/GetByCountryName?countryName=%@", titleForURL]; 
NSString *goodPath [email protected]"http://myURL/CountryStateService.asmx/GetByCountryName?countryName=Canada"; 
if (![path isEqualToString:goodPath]) 
{ 
    NSLog("Two paths are different:\n%@\n%@\n", path, goodPath); 
} 

Je doute qu'il y ait un problème avec le codage. Vous pouvez avoir un espace non autorisé dans votre chaîne de titre.

+0

hmm ... lorsque je consigne le tableau qui est retourné, il semble qu'il y ait un "/ n" à la fin de chaque élément ... curses! – rson

+0

Je ne l'ai pas fait ci-dessus mais je trouve utile de consigner les chaînes entre crochets pour faciliter la recherche des espaces de fin: NSLog ("Deux chemins sont différents: \ n [% @] \ n [% @] \ n ", chemin, goodPath); –