Problème avec subStringFromIndex

jfsgeneva

Membre confirmé
12 Mars 2006
33
1
Bonsoir,

J'aimerais extraire des partie d'une chaine pour les traiter.

Je récupère cette chaine dans un fichier sur un site internet et elle se présente sous cette forme :

["2009/10/22":"heure":"2300","temp":"35","press":"1500"]

J'essaie depuis une semaine d'extraire les chiffres en utilisant un bout de code avec "subStringFromIndex" et "subStringToIndex".

Voici un exemple :
Bloc de code:
NSMutableString *aStr = [[NSMutableString alloc] initWithData:data encoding:NSASCIIStringEncoding];



NSRange range = [aStr rangeOfString:@"\"temp\":"];
int location = range.location;
int length = range.length;
NSString *displayString = [[NSString alloc] initWithFormat:@"Location: %i, length: %i",
location, length];

 NSLog(displayString);
NSString *substring = [aStr substringFromIndex:location];
 NSLog(substring);
Cela devrait me sortir "location=36" "length=8" et me sortir sur la console la fin de la chaine à partir de "35","press":"1500"]

Ca plante en me mettant :

Bloc de code:
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[NSCFString substringFromIndex:]: Range or index out of bounds'
Je ne comprend pas pourquoi.

Si quelqu'un peu m'expliquer ça et me donner un coup de main pour trouver une solution.

Merci.