문제

I'm able to successfully parse the contents of a XML file using TouchXML, but when I try to read an individual NSString, from the NSMutableArray that stores the parsed content, the iPhone app crashes.

My NSLog shows me that the file has been parse as it should, giving this output:

 (
        {
        href = "mms://a19349.l412964549958.c41245496.f.lm.akamaistream.net/D/194359/4125596/v0001/reflector:49944";
    },
        {
        href = "mms://a4322.l4129624350471.c414645296.a.lm.akamaistream.net/D/473432/4129566/v0001/reflector:546441";
    } )

Here is the code I'm using to do the parsing:

NSMutableArray *res = [[NSMutableArray alloc] init];

         .... Parsing happens here ....

Then I try to retrieve the string from the NSMutableArray, using this code (and the app crashes when trying to read this line of code, posted below NSMutableString *string1 = [NSMutableString stringWithString:url];

NSString *url = [[NSString alloc] init];
url = [res objectAtIndex:0];
NSMutableString *string1 = [NSMutableString stringWithString:url];
[string1 deleteCharactersInRange: [string1 rangeOfString: @"href = "]];
[string1 deleteCharactersInRange: [string1 rangeOfString: @";"]];
NSLog(@"Clean URL: %@", string1);

Please, how can I solve this problem? Thank you!

도움이 되었습니까?

해결책

TouchXML returns you an array of NSDictionaries. In order to extract string you need to take value from this NSDictionary:

NSString *url = [[res objectAtIndex:0] objectForKey:@"href"];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top